July 15, 2013 at 5:33 am
raulggonzalez (7/15/2013)
It's funny, though, that if you alias the column, both names can be used (original & alias) in the ORDER BY clause
Try to think of the column alias as a very simple expression
So Col1 AS X = 1 * Col1 AS X
In queries you can sort by expressions AND by the original table columns, even if they are not included in the output. If I include the original column in the output, it should become more clear:
SELECT a AS x -- "Computed" column
,a -- "Original" column
FROM(SELECT 1 AS a) d
ORDER BY
x
,a
[Edit: Added query comments]
Best Regards,
Chris Bรผttner
July 15, 2013 at 7:29 am
Ezpz. Thanks for the question.
July 15, 2013 at 10:29 am
Good Monday question. Nice explanation as well.
Not all gray hairs are Dinosaurs!
July 16, 2013 at 5:12 am
Nice one....
July 16, 2013 at 5:25 am
nice question.... ๐
Manik
You cannot get to the top by sitting on your bottom.
July 17, 2013 at 2:13 am
The explanation says
In T-SQL the nulls are returned at the beginning of the result set if ordering is specified. Standard SQL supports the options NULLS FIRST and NULLS LAST to control how NULLs sort, but T-SQL doesnโt support this option.
For me it's clearer to say that NULLS are treated as the lowest possible value. If you ORDER BY DESC then the NULLs appear at the end of the result set. That's not clear to me from the explanation.
I guess it's just a question of what you mean by 'first' and 'last'. ๐
July 23, 2013 at 12:51 am
Good Question. I've never really thought about Nulls being in a Column that I was ordering. In general the "Order by" Columns tend to the most important Columns in the Result and I wouldn't expect them to contain Null.
David
July 23, 2013 at 7:16 pm
but what order with _the_ null_s_ be returned? no particular order; yes, they both come first, but which before the other? who knows? can't tell.
July 24, 2013 at 7:32 am
Pretty easy. ๐
July 25, 2013 at 10:20 am
kapil_kk (7/14/2013)
Lokesh Vij (7/14/2013)
Easy one for Monday morning ๐Thanks Pramod!
+1 ๐
+1
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 10 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply