Thursday, May 21, 2009

Retrieve the nth highest salrary from an employee table?


3 comments:

  1. SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);

    ReplyDelete
  2. SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);

    Suppose a customer table is having different columns like customer no, payments.What will be the query to select top three max payments?

    SELECT customer_no, payments from customer C1
    WHERE 3<=(SELECT COUNT(*) from customer C2
    WHERE C1.payment <= C2.payment)

    ReplyDelete
  3. Query to find out the number of rows in Oracle Table :

    SELECT COUNT(*) FROM emp;

    ReplyDelete