how to retrieve the top 3 salaries of the table using rownum

Answer Posted / d.elumalai

CREATE TABLE EMP (NAME VARCHAR2(20),SALARY NUMBER(10));

INSERT INTO EMP VALUES('AAA',10000);
INSERT INTO EMP VALUES('BBB',20000);
INSERT INTO EMP VALUES('CCC',30000);
INSERT INTO EMP VALUES('DDD',40000);
INSERT INTO EMP VALUES('EEE',50000);
INSERT INTO EMP VALUES('FFF',60000);
INSERT INTO EMP VALUES('GGG',70000);
INSERT INTO EMP VALUES('HHH',80000);
INSERT INTO EMP VALUES('III',90000);
COMMIT;

SELECT A.* FROM (SELECT name, salary FROM EMP ORDER BY salary DESC) A WHERE ROWNUM<=3;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between nested table and varray?

525


Can function return multiple values in sql?

533


What is pl sql block in dbms?

532


What is sql lookup?

516


Explain the difference between 'between' & 'and' operators in sql

531






What is indexing oracle sql?

566


How do you modify a table in sql?

571


explain the delete statements in sql

585


does sql support programming? : Sql dba

611


What are sql functions? Describe the different types of sql functions?

563


Is sqlite good enough for production?

536


What are different functions in sql?

521


Is ms sql is free?

534


What makes a good primary key?

527


How to handle bulk data?

896