hi can someone tell me this query - Programmers Heaven

Howdy, Stranger!

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

Categories

hi can someone tell me this query

Hi there
I'm using emp(default with oracle software) table . Can anyone tell me what is the query to get 3 maximum sal(salary) drawer . I don't want repeated ans like (3000) .

I mean
5000
3000
2950

thank you
debasis

Comments

  • Geoff-SGeoff-S Posts: 82Member
    : Hi there
    : I'm using emp(default with oracle software) table . Can anyone tell me what is the query to get 3 maximum sal(salary) drawer . I don't want repeated ans like (3000) .
    :
    : I mean
    : 5000
    : 3000
    : 2950
    :
    : thank you
    : debasis
    :
    Hi,
    Don't know about Oracle but in SQL-Server you can prefix the query with "Top 3" ( SELECT Top 3 emp.salary FROM emp) to get what you are after. I would guess thet there must be a similar command in Oracle.
    Hope that helps a bit.
    :-)


  • infidelinfidel Posts: 2,900Member
    : Don't know about Oracle but in SQL-Server you can prefix the query with "Top 3" ( SELECT Top 3 emp.salary FROM emp) to get what you are after. I would guess thet there must be a similar command in Oracle.
    : Hope that helps a bit.

    You'd think there would be but there isn't. At least not as of 9i.

    You have to compare the rownum to some constant, but you have to do it *after* ordering the results, like this:

    [code]
    select * from (
    select * from emp
    order by salary desc
    )
    where rownum <= 3
    [/code]


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.