Which one is better in SQL Server 2008 or it doesn't matter as the database optimizes.
SELECT * FROM table
WHERE datecolumn = (SELECT max(datecolumn) FROM table);
SELECT TOP 1 * FROM table ORDER BY datecolumn DESC;
Looking at the actual SQL execution plan for these queries, it results in exactly the same execution plan and the same execution cost. However it might differ depending on the index setup and collected statistics, therefore it is best to do the check yourself.
One thing to be aware of is that the two queries might not return the same result. The 2nd SQL will always return one record where the first record might return multiple rows if datecolumn
is not unique.
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