Results 1 to 3 of 3

Thread: get top 2

  1. #1
    Join Date
    Nov 2005
    Posts
    1

    Unanswered: get top 2

    i have this record in my table

    name income
    john 4500
    peter 4500
    jake 3000
    jane 3000
    paul 2000
    gorge 1000

    if i use the SELECT TOP 2 it will return me john and peter only how can i query to return me the 2 biggest income. that will return john peter jake and jane
    thx.. just a newbie sory..

  2. #2
    Join Date
    Dec 2002
    Posts
    1,245
    Quote Originally Posted by naideih
    i have this record in my table

    name income
    john 4500
    peter 4500
    jake 3000
    jane 3000
    paul 2000
    gorge 1000

    if i use the SELECT TOP 2 it will return me john and peter only how can i query to return me the 2 biggest income. that will return john peter jake and jane
    thx.. just a newbie sory..
    use ORDER BY. As in

    SELECT TOP 2 *
    FROM MyTable
    ORDER BY income DESC

    Regards,

    hmscott
    Have you hugged your backup today?

  3. #3
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    hi

    try this

    SELECT
    namefield
    FROM
    yourtable
    WHERE
    incomefield
    IN
    (SELECT DISTINCT TOP 2 incomefield FROM yourtable ORDER BY incomefield DESC)
    Cheers....

    baburajv

Posting Permissions

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