Suppose:
WITH t12 AS (SELECT * FROM t1 INNER JOIN t2 ON (t1.id = t2.id))
SELECT * FROM t12
This will fail with:
The column 'id' was specified multiple times for 't12'.
Now this is a large query as t1
and t2
have many (+200) columns. I am not to list them all: I explicitly want to use the *
.
Normally I would solve this with the USING (id)
clause, but SQL Server doesn't seem to support that. Any ideas?
Other option is to work without the WITH
clause -- which works but makes the code less readable.
There are many answers on SO that make you list all fields. This is an explicit question to do it without, in the WITH clause and in pure SQL. Related questions like "exclusion fields" here and here and one for views ask for non-ANSI SQL capabilities. This question is targeted for pure SQL and would be possible (as far as I understand) if SQL Server supported ANSI SQL-92 syntax.