簡體   English   中英

SQL交叉聯接查詢不適用於變量

[英]SQL Cross Join Query not working with variable

這種交叉連接可以正常工作:

select * from x, y

我正在嘗試運行此查詢:

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

但我收到此錯誤消息:

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

表x和y具有相同的列和列定義。

有什么想法/建議嗎?

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

您要為兩個具有相同名稱的表別名。 嘗試:

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

您必須在內部查詢部分中指定列名稱。 像這樣的東西:

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

除了Lock的答案,您還忘記了逗號:

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

更好的是,使用ansi 1992表示法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM