How To Return Top 5 Rows in Oracle?
Submitted by: AdministratorIf 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;
<pre>EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- -------------
100 Steven King
101 Neena Kochhar
102 Lex De Haan
103 Alexander Hunold
104 Bruce Ernst</pre>
Submitted by: Administrator
SQL> SELECT employee_id, first_name, last_name
FROM employees WHERE ROWNUM <= 5;
<pre>EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- -------------
100 Steven King
101 Neena Kochhar
102 Lex De Haan
103 Alexander Hunold
104 Bruce Ernst</pre>
Submitted by: Administrator
Read Online Oracle Database Job Interview Questions And Answers
Top Oracle Database Questions
☺ | How To Shutdown Your 10g XE Server? |
☺ | How To Write Date and Time Interval Literals in Oracle? |
☺ | How To Run SQL*Plus Commands in SQL Developer? |
☺ | How To Use "OUT" Parameter Properly? |
☺ | What Is the Relation of a User Account and a Schema? |
Top DB Oracle Categories
☺ | Oracle PL-SQL Interview Questions. |
☺ | Oracle DBA Interview Questions. |
☺ | Oracle D2K Interview Questions. |
☺ | OCI Interview Questions. |
☺ | Forms Reports Interview Questions. |