943,905 Members | Top Members by Rank

Ad:
  • Oracle Discussion Thread
  • Unsolved
  • Views: 3450
  • Oracle RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 27th, 2009
0

how to display only the first 3 rows

Expand Post »
Please how can I write a query to display only the top three earners in a table in desc order e.g
Emp Sal
John 100
Jam 120
Abi 90
Jo 170
the query should display
Emp Sal
John 200
Jam 170

thanks
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
achiman is offline Offline
51 posts
since Mar 2009
Mar 27th, 2009
0

Re: how to display only the first 3 rows

I have tried using numrow but it doesnt do the job
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
achiman is offline Offline
51 posts
since Mar 2009
Mar 27th, 2009
0

Re: how to display only the first 3 rows

please is there any function called rank in oracle and how can i use it
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
achiman is offline Offline
51 posts
since Mar 2009
Mar 27th, 2009
0

Re: how to display only the first 3 rows

rank does not work maybe because im using oracle8i
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
achiman is offline Offline
51 posts
since Mar 2009
Mar 30th, 2009
0

Re: how to display only the first 3 rows

Try this

sql Syntax (Toggle Plain Text)
  1. SELECT * FROM emp WHERE rownum<4 ORDER BY sal desc
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
May 31st, 2009
0

Re: how to display only the first 3 rows

ya what debasisdas wrote works for ur query
Reputation Points: 10
Solved Threads: 1
Newbie Poster
manuhar is offline Offline
11 posts
since May 2009
Jun 18th, 2009
0

Re: how to display only the first 3 rows

Click to Expand / Collapse  Quote originally posted by debasisdas ...
Try this

sql Syntax (Toggle Plain Text)
  1. SELECT * FROM emp WHERE rownum<4 ORDER BY sal desc
Hello,

Before solution is incorrect.

The good solution:

sql Syntax (Toggle Plain Text)
  1. SELECT *
  2. FROM (SELECT *
  3. FROM emp
  4. ORDER BY sal DESC)
  5. WHERE ROWNUM <= 3

First step - Obtain the records with all fields in the correct order (view-inline)
Second step - Cut the records in the 3 (Top1-query)
Last edited by peter_budo; Jun 19th, 2009 at 1:05 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
anubina is offline Offline
17 posts
since Jun 2009
Jul 14th, 2009
0

Re: how to display only the first 3 rows

I hope this query also may help:

Select top(3) from emp order by sal DESC
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kishor_12 is offline Offline
1 posts
since Jul 2009
Jul 14th, 2009
0

Re: how to display only the first 3 rows

There is no Top in Oracle. That is SQL Server syntax.
Reputation Points: 91
Solved Threads: 18
Junior Poster
cgyrob is offline Offline
125 posts
since Sep 2008
Jul 15th, 2009
0

Re: how to display only the first 3 rows

Click to Expand / Collapse  Quote originally posted by Kishor_12 ...
I hope this query also may help:

Select top(3) from emp order by sal DESC
You need to read question properly before answering to them. This is oracle forum not sql server.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Oracle Forum Timeline: Find Oracle Tables that contain a specific field
Next Thread in Oracle Forum Timeline: problem.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC