TOP, LIMIT, ROWNUM in SQL:
If you want to fetch top N rows from table, you can use TOP clause. This clause is useful when a table contains thousands of records because returning so many records can impact the performance.
But all databases may not support TOP clause.
SQL Server – TOP
MySQL supports LIMIT clause to select limited number of rows.
Oracle server supports ROWNUM
SQL Server/MS Access:
select TOP 5 * from users;
select * from users LIMIT 5;
select * from users where ROWNUM<=5;
SQL TOP PERCENT:
Below sql statement fetches the first 25% of records from users table.
select TOP 25 PERCENT * from users;
WHERE clause in TOP/LIMIT/ROWNUM:
select TOP 5 * from users where state=’california’;
select * from users where state=’california’ LIMIT 5;
select * from users where where state=’california’ AND ROWNUM<=5;