Tough SQL Queries - Part 9
These questions asked in most of the interviews: 1 . To FETCH ALTERNATE records FROM a table . ( EVEN NUMBERED ) SELECT * FROM emp WHERE rowid IN ( SELECT decode ( mod ( rownum , 2 ), 0 , rowid , NULL ) FROM emp ); 2 . To SELECT ALTERNATE records FROM a table . ( ODD NUMBERED ) SELECT * FROM emp WHERE rowid IN ( SELECT decode ( mod ( rownum , 2 ), 0 , NULL , rowid ) FROM emp ); 3 . Find the 3 rd MAX salary IN the emp table . SELECT DISTINCT sal FROM emp e1 WHERE 3 = ( SELECT count ( DISTINCT sal ) FROM emp e2 WHERE e1 . sal <= e2 . sal ); 4 . Find the 3 rd MIN salary IN the emp table . SELECT DISTINCT sal FROM emp e1 WHERE 3 = ( SELECT count ( DISTINCT sal ) FROM emp e2 WHERE e1 . sal >= e2 . sal ); 5 . Select FIRST n records FROM a table . SELECT * FROM emp WHERE rownum <= n ; 6 . Select LAST n records FR...