Search code examples
sqlsql-servervariablescross-join

SQL Cross Join Query not working with variable


This cross join works fine:

select * from x, y

I am trying to run this query:

select abc.col1 from abc
(select * from x, y) abc

But I get this error message:

Msg 8156, Level 16, State 1, Line 2
The column 'col1' was specified multiple times for 'abc'.

Both tables x and y have the same columns and column definitions.

Any ideas/suggestions?


Solution

  • select abc.col1 from abc
    (select * from x, y) abc
    

    You are aliasing two tables with the same name. Try:

    select abc.col1 from abc,
    (select x.* from x, y) abc2