SQL SELECT LIMIT, TOP, ROWNUM

SQL SELECT LIMIT, TOP, ROWNUM clauses are used to limit the number of retrieved records. SQL SELECT LIMIT, TOP, ROWNUM clauses are very useful to databases having lot of records, this clause helps to return limited number of results instead of all records. For large databases it takes lot of time to retrieve all the results.

SQL SELECT LIMIT, TOP, ROWNUM clauses, every database it is used differently. For SQL Server / MS Access Syntax – SELECT TOP clause will be used. For MySQL database – SELECT LIMIT clause will be used. For Oracle Database – SELECT ROWNUM clause will be used.

SQL Server / MS Access Syntax – SQL SELECT TOP :

SELECT TOP number|percent column_name(s)
FROM table_name;

SQL Server / MS Access Syntax Example

SELECT TOP 3 column_name(s)
FROM Users;
SELECT TOP 50 PERCENT column_name(s)
FROM Users;

MySQL Syntax – SQL SELECT LIMIT :

SELECT column_name(s)
FROM table_name
LIMIT number;

MySQL Example

SELECT *
FROM Users
LIMIT 3;

Oracle Syntax – SQL SELECT ROWNUM :

SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number;

Oracle Example

SELECT *
FROM Users
WHERE ROWNUM <=3;

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe