I'm just trying to add in an the newest estimated return date for a car as part of a subquery in my Select statement, I just wanted to know if this was how it is done?
I think I heard that Select happens before Order By so wanted to do a quick check.
select top 1 ESTIMATE_RETURN_DATE
from CHECK.AOS
where AOS.AUTO_NO = CHECK_EVENT.AUTONUM_4
ORDER BY REVISION_NO desc
ORDER BY is evaluated before the SELECT, as the ordering changes the results returned.
TOP 1 also ensures the lowest REVISION_NO is returned, therefore it appears you are using the query correctly.
Yes Top works after OrderBY. First it will find all the records and then it would apply Top. So you are doing it right. I am also writing down the order in which a query process in sql server
FROM
WHERE
GROUP BY
HAVING
SELECT
ORDER BY
TOP/OFFSET FETCH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With