I'm new to SQL and wondering is it possible to select the bottom n rows without using SELECT TOP
and then ORDER BY
.
I can find numerous examples of mimicing the idea with SELECT TOP
& then ORDER BY
e.g. How to select bottom most rows? but I need to keep my data sorted in the opposite order so using ORDER BY
isn't ideal.
My below query returns the data points I need to pass through to my other programmes but now the data comes out sorted in the opposite direction than desired and causes issues.
SELECT TOP 504
date
,price
FROM
[dbo].[AssetRet]
WHERE
asset = 'SP500'
ORDER BY
date DESC
I could get round this by putting a filter on date
on remove TOP
but I'm not sure how to do this i.e.:
WHERE
date > Min(Select DISTINCT TOP 504 date FROM [dbo].[AssetRet] ORDER BY date DESC)
I hope it is possible via SQL to SELECT BOTTOM
without ORDER BY
; else I will have to just flip the data after the SQL query in the other program