2011-07-19 60 views
0

對於下面的查詢,執行SQL JOIN表上

SELECT columnA 
FROM XYZ JOIN XDE 
ON XYZ.columnA=XDE.columnA 

我得到這個錯誤,

Msg 209, Level 16, State 1, Line 1 
Ambiguous column name 'columnA'. 

其中XYZ和XDE是表名,

Table: XYZ

Table: XDE

爲什麼它不能在SQL Server 2005中工作?

回答

3

您需要定義columnA來自哪個表,因爲它存在於連接中列出的兩個表中。例如:

SELECT XYZ.columnA 
FROM XYZ JOIN XDE 
ON XYZ.columnA=XDE.columnA 
1

因爲您沒有指定從哪個表中選擇ColumnA。

SELECT XYZ.columnA 
FROM XYZ JOIN XDE 
ON XYZ.columnA=XDE.columnA 

應該這樣做。