SQL Server : inner join: ambiguous name

I have two tables in SQL Server:

[Production].[dbo].[OrderDetails]:

CaseId    Gender
-----------------
698       Female
694       Male
676       Male
659       Male
636       Female
624       Female
622       Female
597       Male
579       Male
574       Male

[Production].[dbo].[Order]

OrderID   SoftAdminOrderID    InfoIDOrderID   Active      
----------------------------------------------------
33425999      698             196665           1
33425984      694             196662           1
33425984      694             196663           0   
33425609      676             196645           1
33425270      659             196625           1
33424973      636             196609           1
33424716      624             196594           1
33424704      622             196592           1
33424500      597             196568           1
33424340      579             196552           1
33424281      574             196548           1

and I want to obtain the gender with an inner join:

 SELECT TOP (10) 
     [OrderID],
     [SoftAdminOrderID],
     [InfoID],
     [Active],
    /* [Gender]*/
 FROM
     [Production].[dbo].[Order]
 /*INNER JOIN 
     [Production].[dbo].[OrderDetails] ON [Production].[dbo].[Order].SoftAdminOrderID = [Production].[dbo].[OrderDetails].CaseId*/
 where Active = 1
 order by SoftAdminOrderID desc

But I get an error when I remove the comment from the inner join:

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

I do not understand why it is considered ambiguous.


如果真的发生了,那么你为什么不通过向列添加表别名来解决它:

SELECT TOP (10) 
    o.[OrderID]
    ,o.[SoftAdminOrderID]
    ,o.[InfoID]
    ,od.[Gender]
 FROM [Production].[dbo].[Order] AS o
 INNER JOIN [Production].[dbo].[OrderDetails] AS od ON o.SoftAdminOrderID = od.CaseId
链接地址: http://www.djcxy.com/p/86294.html

上一篇: 我的C ++输出始终为0

下一篇: SQL Server:内部连接:模糊名称