All for Joomla All for Webmasters

SQL ORDER BY LIMIT

We can retrieve limited rows from the database. I can be used in pagination where are forced to show only limited records like 10, 50, 100 etc.

LIMIT CLAUSE FOR ORACLE SQL:

If you want to use LIMIT clause with SQL, you have to use ROWNUM queries because it is used after result are selected.

You should use the following code:

  1. SELECT name, age
  2. FROM
  3. (SELECT name, age, ROWNUM r
  4. FROM
  5. (SELECT name, age, FROM employee_data
  6. ORDER BY age DESC
  7. )
  8. WHERE ROWNUM <=40
  9. )
  10. WHERE r >= 21;

This query will give you 21th to 40th rows.

PinIt
submit to reddit

Leave a Reply

Top