SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Return Top 5 Rows?

Go down

How To Return Top 5 Rows? Empty How To Return Top 5 Rows?

Post by Micheal Sun Jan 17, 2010 3:22 am

If you want the query to return only the first 5 rows, you can use the pseudo column called
ROWNUM in the WHERE clause. ROWNUM contains the row number of each returning row from
the query. The following statement returns the first 5 rows from the employees table:
SQL> SELECT employee_id, first_name, last_name
FROM employees WHERE ROWNUM <= 5;
EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- -------------------------
100 Steven King
101 Neena Kochhar
102 Lex De Haan
103 Alexander Hunold
104 Bruce Ernst

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum