[英]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. 表x和y具有相同的列和列定义。
Any ideas/suggestions? 有什么想法/建议吗?
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
you have to specify column name in inner query section. 您必须在内部查询部分中指定列名称。 something like this: 像这样的东西:
select abc.col1 from abc
(select x.col1,y.col1 from x, y) abc
In addition to Lock's answer, you also forgot the comma: 除了Lock的答案,您还忘记了逗号:
select
abc.col1
from abc, (select * from x, y) abc2
Even better, using the ansi 1992 notation: 更好的是,使用ansi 1992表示法:
select
abc.col1
from abc CROSS JOIN (select * from x, y) abc2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.