Tuesday, December 20, 2005

SQL Trivia

Got this nice little pop quiz at work (which you are obviously bound to answer wrong).

Given the next SQL Script:



What would the output of the SELECT be?
Now my first reaction was obviously 3, 2, 1 and this would be correct on SQL Server 2005 but unfortunately SQL Server 2000 gives you 1, 2, 3.

Quite frankly I prefer the SQL Server 2005 method anyway ;-)

I lost :-(

2 comments:

Denis said...

Here is some more fun

create table #test (id int identity,AlphaChar char(1))

insert into #test
select 'a' union all
select 'z' union all
select 'b' union all
select 'y'

select id as AlphaChar from #test
order by AlphaChar

select id as AlphaChar,AlphaChar from #test
order by AlphaChar

WesleyB said...

Hehe very nice :-)

On SQL Server 2005 it does what I personally like the most...
Msg 209, Level 16, State 1, Line 12
Ambiguous column name 'AlphaChar'.

Thanks for the nice addition.