I have two tables with identical schema in SQL Server 2008 R2. If I execute the following query, with parentheses intact, I get results from both tables.
/*
select distinct Name, Rank, SerNo, OtherStuff from
*/
(
select Name, Rank, SerNo, OtherStuff from OldPlayers
union
select Name, Rank, SerNo, OtherStuff from NewPlayers
)
/*
OldPlayers
*/
go
If I then uncomment both comments, and comment out the expression in parentheses, I also get results (from one table, of course).
If I now re-comment the table name at the end, and uncomment the parenthetical expression so that it can replace the table name, I get the error “Incorrect syntax near ‘)’.”
Why can’t I substitute the union expression for the table name?
If you try it like this: