Subselect in MS SQL Server 2005?

RichieZ

Diamond Member
Jun 1, 2000
6,551
40
91
I am playing around with MS SQL Server Dev Edition SP2.

What is wrong with this query:
select * from
(select * from adventureworks.person.contact)

it throws the error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ')'.

but if i give it a correlation name it works fine:
select * from
(select * from adventureworks.person.contact) as x

Yes this is a useless query (its just an example) and i could accomplish many of the things I want to do with the proper joins and unions, but i need to do some quick and dirty data validation. As far as I remember this kind of thing worked fine in Oracle.
 

KLin

Lifer
Feb 29, 2000
30,454
763
126
you have to define a subquery with an alias to do a select statement against it. It will always throw that error if you don't give it an alias. FYI, you don't need the as keyword. Using ) x would work too.