Database & SQL

Moderators: None (Apply to moderate this forum)
Number of threads: 1174
Number of posts: 2221

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
hi can someone tell me this query Posted by talk_to_deb on 24 Oct 2004 at 3:22 PM
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
Report
Re: hi can someone tell me this query Posted by Geoff-S on 25 Oct 2004 at 2:14 AM
: 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.



Report
Re: hi can someone tell me this query Posted by infidel on 25 Oct 2004 at 8:15 AM
: 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:

select * from (
    select * from emp
    order by salary desc
)
where rownum <= 3



infidel

$ select * from users where clue > 0
no rows returned





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.