On 4/29/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I am updating some code from SQL to Oracle. What is the eqivalent of this 
> T-SQL statement
> 
> SELECT TOP 5 * FROM foo:
> 

If you have an ORDER BY clause, then you must use this syntax:

SELECT *
FROM
(
SELECT mycolumn1,
 mycolumn2,
 etc.
FROM foo
ORDER BY mycolumn1
)
WHERE rownum <= 5

The reason you have to use an inner view like this is because Oracle
will apply the rownum predicate to the result set *before* the ORDER
BY clause, which means that you won't necessarily get the correct top
5.

If there is no ORDER BY clause, you can simply do:

SELECT mycolumn1,
 mycolumn2,
 etc.
FROM foo
WHERE rownum <= 5

Regards,
Dave.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:205126
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to