awsome
awsome

Reputation: 2153

select the n-1 rows of a query

I am usung oracle 11g. Suppose the following query returns n rows.

SELECT t.id,t.from_date,t.price  FROM prices t order by id, date

And i want only first n-1 rows from the query. How can i possibly do that without using inner queries?

Upvotes: 4

Views: 3921

Answers (1)

Joe Stefanelli
Joe Stefanelli

Reputation: 135808

EDIT: Modified based upon additional information added to question.

select p.id, p.from_date, p.price
    from (select id, from_date, price, row_number() over (order by id desc) as r from prices) p
    where p.r <> 1
    order by p.id, p.from_date

Upvotes: 6

Related Questions