Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select last 12 rows oracle

Tags:

select

oracle

I want to do a select in oracle that returns more or less 300 rows, but I just want the 12 last registries. Here is the query:

(SELECT * 
FROM series 
ORDER BY odata DESC) estatisticas 
WHERE ponteiro = 50 AND lotus = 30
like image 395
Klaus Seidel Avatar asked Jan 16 '23 21:01

Klaus Seidel


1 Answers

Something along the lines of:

select * from 
    ( select estatisticas, rownum rn
        (SELECT *
        FROM series 
        ORDER BY odata DESC) estatisticas 
        WHERE ponteiro = 50 AND lotus = 30
    order by odata asc) where rownum <=12

Edit: updated it for your query, you want to sort it opposite of the inner query, ascending in your case, so you can get the last 12

like image 117
Chris Avatar answered Jan 25 '23 18:01

Chris