how to display only the first 3 rows

Reply

Join Date: Mar 2009
Posts: 27
Reputation: achiman is an unknown quantity at this point 
Solved Threads: 0
achiman achiman is offline Offline
Light Poster

how to display only the first 3 rows

 
0
  #1
Mar 27th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 27
Reputation: achiman is an unknown quantity at this point 
Solved Threads: 0
achiman achiman is offline Offline
Light Poster

Re: how to display only the first 3 rows

 
0
  #2
Mar 27th, 2009
I have tried using numrow but it doesnt do the job
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 27
Reputation: achiman is an unknown quantity at this point 
Solved Threads: 0
achiman achiman is offline Offline
Light Poster

Re: how to display only the first 3 rows

 
0
  #3
Mar 27th, 2009
please is there any function called rank in oracle and how can i use it
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 27
Reputation: achiman is an unknown quantity at this point 
Solved Threads: 0
achiman achiman is offline Offline
Light Poster

Re: how to display only the first 3 rows

 
0
  #4
Mar 27th, 2009
rank does not work maybe because im using oracle8i
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,144
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 132
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: how to display only the first 3 rows

 
0
  #5
Mar 30th, 2009
Try this

  1. SELECT * FROM emp WHERE rownum<4 ORDER BY sal desc
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: manuhar is an unknown quantity at this point 
Solved Threads: 0
manuhar manuhar is offline Offline
Newbie Poster

Re: how to display only the first 3 rows

 
0
  #6
May 31st, 2009
ya what debasisdas wrote works for ur query
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 13
Reputation: anubina is an unknown quantity at this point 
Solved Threads: 1
anubina anubina is offline Offline
Newbie Poster

Re: how to display only the first 3 rows

 
0
  #7
Jun 18th, 2009
Originally Posted by debasisdas View Post
Try this

  1. SELECT * FROM emp WHERE rownum<4 ORDER BY sal desc
Hello,

Before solution is incorrect.

The good solution:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 1
Reputation: Kishor_12 is an unknown quantity at this point 
Solved Threads: 0
Kishor_12 Kishor_12 is offline Offline
Newbie Poster

Re: how to display only the first 3 rows

 
0
  #8
Jul 14th, 2009
I hope this query also may help:

Select top(3) from emp order by sal DESC
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 123
Reputation: cgyrob is on a distinguished road 
Solved Threads: 18
cgyrob's Avatar
cgyrob cgyrob is offline Offline
Junior Poster

Re: how to display only the first 3 rows

 
0
  #9
Jul 14th, 2009
There is no Top in Oracle. That is SQL Server syntax.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,144
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 132
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: how to display only the first 3 rows

 
0
  #10
Jul 15th, 2009
Originally Posted by Kishor_12 View Post
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.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2283 | Replies: 13
Thread Tools Search this Thread



Tag cloud for Oracle
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC