Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002
    Posts
    35

    Unanswered: Second highest value

    Hi,

    In db2 V 7 , how to get the second highest value( row) from a table in a single query. ( I mean without opening a fetch).

    Can any one help me please.

    Thanks for the help in advance.

    Thanks,
    vasu
    vasu

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Second highest value

    Straight from my head ,
    select max(salary) from table1 where salary <> (select max(salary) from table1)

    Am sure, there are better methods ..

    Cheers

    sathyaram

    Originally posted by k_vasu
    Hi,

    In db2 V 7 , how to get the second highest value( row) from a table in a single query. ( I mean without opening a fetch).

    Can any one help me please.

    Thanks for the help in advance.

    Thanks,
    vasu
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Second highest value

    From SQL cookbook

    select * from employee e1 where (select count(distinct salary) from
    employee e2 where e2.salary>=e1.salary)=2
    Visit the new-look IDUG Website , register to gain access to the excellent content.

Posting Permissions

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