How To Return Top 5 Rows?
Page 1 of 1
How To Return Top 5 Rows?
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
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
Similar topics
» How To Select Some Rows from a Table?
» How To Select All Columns of All Rows from a Table?
» How To Filter Out Duplications in the Returning Rows?
» How To Use SELECT Statement to Count the Number of Rows?
» What Privilege Is Needed for a User to Insert Rows to Tables in Another Schema?
» How To Select All Columns of All Rows from a Table?
» How To Filter Out Duplications in the Returning Rows?
» How To Use SELECT Statement to Count the Number of Rows?
» What Privilege Is Needed for a User to Insert Rows to Tables in Another Schema?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal