I really liked it, so my second response !
Sergiy (3/17/2013)
Lynn Pettis (3/17/2013)
Really, CTEs arecomplex? I find them to make writing queries easier as you don't have to write derived tables.
🙂
Let's compare:
;WITH MyData AS (
SELECT TOP 2 *
FROM dbo.NFFeeds
ORDER BY id DESC
)
SELECT * FROM MyData
ORDER BY id
VS.
SELECT * FROM (
SELECT TOP 2 *
FROM dbo.NFFeeds
ORDER BY id DESC) MyData
ORDER BY id
Derived table wins as it does not contain extra words ";WITH MyData AS ".
Apparently, CTE's are more complex comparing to derived tables.
😎
I want to be part of your competition. So, my version wins over yours one as it contains less number of characters:
SELECT * FROM (SELECT TOP 2 * FROM dbo.NFFeeds ORDER BY id DESC) m ORDER BY id
It wins as:
1. It has less New Line characters
2. It doesn't have tabs (or extra spaces) for indent
3. Most important one - my alias "m" is 7 (seven!) times shorter than yours one "MyData"!
May I have a medal now?
:hehe::hehe::hehe::hehe::hehe: