Reputation: 152
SELECT doesntmatterwhat
FROM whatever
OFFSET 3 LIMIT 2
How would I reproduce this, but WITHOUT using LIMIT
or OFFSET
to select the last 3 rows but the last one
Upvotes: 2
Views: 115
Reputation: 152
This was the solution I was looking for. Thanks for helping though.
SELECT doesntmatterwhat
FROM whatever
ORDER BY 1
OFFSET 3 ROWS
FETCH FIRST 2 ROWS ONLY;
Upvotes: 1
Reputation: 15061
SELECT TOP 2 FROM (
SELECT TOP 3 doesntmatterwhat
FROM whatever
) a
ORDER BY doesntmatterwhat
Not using TOP
SELECT n.doesntmatterwhat
FROM (SELECT n.doesntmatterwhat, row_number() OVER (ORDER BY date DESC) AS sequence
FROM whatever n
) n
WHERE n.sequence>= 2 AND n.sequence<= 3;
Upvotes: 1