Wednesday 18 September 2013

Fetch random rows from database(Oracle,MySql,MS Sql).

In this article, I have explained how to fetch random rows from database (Oracle,MySql,Ms Sql).
This is usefull when you have to show random information like articles,pages,links to user.There are various way to fetch random rows from table.But here I have show you in easy way to do from sql.

Oracle:-

SELECT column FROM
(
SELECT column FROM Table
ORDER BY dbms_random.value
)
WHERE rownum <= 10;

MySql:-

SELECT column FROM table
ORDER BY RAND()
LIMIT 10;

MS Sql:-


SELECT top 1 * FROM Employee_Demo ORDER BY NEWID();

No comments:

Post a Comment

Note: only a member of this blog may post a comment.