Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old May 13th, 2004, 02:24 PM
newmem newmem is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 4 newmem User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question select query..

Is it possible to select top 1 row from a recordset sorted on a column?

e.g The select query pulls data from 3 different tables which are joined and sorted on a date column of table 1. But I'm interested in the first row returned by the select query.

In SQL server, one can write :
select top 1 t1.col1,t2.col2, t2.col3 from t1,t2 where
t1.col1 = t2.col1

How do I get similar results in an Oracle query?

Thanks

Reply With Quote
  #2  
Old May 13th, 2004, 08:47 PM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Yes, you can get the top first (1st) record from the table, but little bit difficult in Oracle, Oracle provides in line view fuctionality to do so, For example:

SELECT * FROM (SELECT * FROM emp)
WHERE rownum<2
/

If you want to get the top first record of a result set in specified order, it will be more difficult and complicated, look at the following example:

SELECT * FROM (SELECT * FROM emp,deptno where emp.deptno=dept.deptno ORDER BY sal DESC)
WHERE rownum<2
/

You can get the top first record of any result set as shown above, no matter either data is fetching from one table or more than one table. Look at another example:

SELECT * FROM (SELECT a.empno,a.ename,a.sal,b.deptno FROM emp a,dept b where a.deptno=b.deptno ORDER BY a.sal DESC)
WHERE rownum<2

Regards,

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > select query..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway