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 sqlservr exe?

694


What are sql triggers used for?

722


what is a constraint? : Sql dba

882


Why cross join is used?

825


Does sql view stored data?

722






Why we use cross join?

703


What is multiple columns?

778


What is pl sql block in dbms?

708


What is insert command in sql?

771


what are the advantages a stored procedure? : Sql dba

710


Can you upgrade sql express to full sql?

709


Can we use loop in sql?

727


How can you load microsoft excel data into oracle? : aql loader

811


What is an exception in pl/sql?

725


what are date and time data types? : Sql dba

702