Limit the query to display only the top 3 highest paid employees. : ROWNUM « Select Query « Oracle PL / SQL






Limit the query to display only the top 3 highest paid employees.

   

create table employee(
         emp_no                 integer         primary key
        ,lastname               varchar2(20)    not null
        ,salary                 number(3)
);

insert into employee(emp_no,lastname,salary)
              values(1,'Tomy',2);

insert into employee(emp_no,lastname,salary)
              values(2,'Jacky',3);

insert into employee(emp_no,lastname,salary)
              values(3,'Joey',4);

insert into employee(emp_no,lastname,salary)
              values(4,'Janey',5);


select lastname,  salary
from (SELECT lastname, salary FROM employee ORDER BY salary DESC)
where rownum <= 3 ;


LASTNAME                 SALARY
-------------------- ----------
Janey                         5
Joey                          4
Jacky                         3



drop table employee;


   
    
  








Related examples in the same category

1.Use rownum in select clause
2.Use rownum in update set statement
3.Use rownum in where clause to control the row count
4.Use rownum column with order by
5.Use rownum in where clause to limit the row count
6.Use rownum to limit the subquery
7.Use rownum = 1 and select into
8.Retrieving the Top Five Students with ROWNUM
9.Getting the Five Most Expensive Products