Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Unhappy Unanswered: 2nd highest record

    select ename,empno,sal
    from emp
    where sal<(select max (sal)
    from emp);

    in this query i only need 2nd record
    but it is executing all records

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    This might be one way to do that:
    Code:
    select * 
    from (select empno, ename, sal,
          rank() over (order by sal desc) rb 
          from emp
         )
    where rb = 2;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •