Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When did oracle start supporting "top": select top ? p2_.PRODUCT_ID from PRODUCT?

Tags:

oracle

When did oracle start supporting "top":

select top ? p2_.PRODUCT_ID from PRODUCT?
like image 495
jon077 Avatar asked Apr 22 '09 17:04

jon077


People also ask

Does Oracle support top clause?

The SQL SELECT TOP Clause Note: Not all database systems support the SELECT TOP clause. MySQL supports the LIMIT clause to select a limited number of records, while Oracle uses FETCH FIRST n ROWS ONLY and ROWNUM .


1 Answers

I am not sure ORACLE ever had a TOP function. You want to use a TOP-N query.

For example:

select  *
  from  (SELECT  *
           FROM  foo
          where  foo_id=[number]
       order by  foo_id desc)
 where  rownum <= 3   

This will get you the top three results (because I order by desc in the sub query)

like image 80
northpole Avatar answered Dec 18 '22 14:12

northpole