a select to retreive the 10 max values from a table

i am rather a newbie...but i was wonder what select statement i can use to retreieve the 10 top values from a table...for instance the 10 books that sell the most....

Select title, author, price, noofsales where noofsales between ????

if use between i need 2 values the MAX(noofsales) that would give me one value for the between..how do i find the 10 value?

or is there another select one could use?



Comments

  • : i am rather a newbie...but i was wonder what select statement i can use to retreieve the 10 top values from a table...for instance the 10 books that sell the most....
    :
    : Select title, author, price, noofsales where noofsales between ????
    :
    : if use between i need 2 values the MAX(noofsales) that would give me one value for the between..how do i find the 10 value?
    :
    : or is there another select one could use?

    It depends some on which database you are using. With newer versions of Informix, I think you can do "select first 10 title, author...". With Oracle, you can do:

    [code]
    Select *
    from (select title, author, price, noofsales
    from table
    order by noofsales desc)
    where rownum < 11
    [/code]
  • In SQL Server you can use SELECT TOP 10 * FROM .....
    /Chris
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories