|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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, |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > select query.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|