Article:
  SQL Data Types
Subject:   how do we find nth highest in SQL
Date:   2004-11-14 21:40:07
From:   Question&answer
Response to: how do we find nth highest in SQL

To find the nth highest salary as below


select max(a.sal) from emp a where &n=(select count(b.sal) from emp b where (a.sal output-
put the value of n and get the highest salary that u have give the number i;e 4,5,6,10 etc.


thanx,
Haribrat


Full Threads Newest First

Showing messages 1 through 5 of 5.

  • how do we find nth highest in SQL
    2004-12-11 08:16:41  RuchirAwadhawal [View]

    Query for Nth Max (Highest)
    select sal from emp t
    where &n = (select count(sal)
    from (select distinct sal from emp)
    where t.sal<=sal);

    <b>Query for Nth Min (Lowest)
    select sal from emp t
    where &n = (select count(sal)
    from (select distinct sal from emp)
    where t.sal>=sal);
    • query for nth max
      2007-08-25 02:05:46  kashif094 [View]

      select * from emp e where 1=(select count(distinct sal) from emp where e.sal<=sal)



      hi i am kashif can anyone tell me what is the concept of 1 in this query?
      • query for nth max
        2007-10-25 05:02:21  jolly_cet [View]

        1 specifies the position..
  • how do we find nth highest in SQL
    2004-12-11 08:17:00  RuchirAwadhawal [View]

    Query for Nth Max (Highest)
    select sal from emp t
    where &n = (select count(sal)
    from (select distinct sal from emp)
    where t.sal<=sal);

    <b>Query for Nth Min (Lowest)
    select sal from emp t
    where &n = (select count(sal)
    from (select distinct sal from emp)
    where t.sal>=sal);
    • how do we find nth highest in SQL
      2005-01-18 21:03:32  hiexplain [View]

      thanks a lot
      "select sal from emp t
      where &n = (select count(sal)
      from (select distinct sal from emp)
      where t.sal<=sal);"
      it is working fine
      could u please let me know how it works...
      thanks and reguards
      surendra