SQL Server:内部连接:模糊名称
我在SQL Server中有两个表:
[制造] [DBO] [订单明细]。:
CaseId Gender
-----------------
698 Female
694 Male
676 Male
659 Male
636 Female
624 Female
622 Female
597 Male
579 Male
574 Male
[制造] [DBO]。[在线订购]
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
我想用内部连接来获得性别:
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
但是,当我从内部联接删除注释时出现错误:
Msg 209,Level 16,State 1,Line 58
不明确的列名'CaseId'。
我不明白为什么它被认为是模棱两可的。
如果真的发生了,那么你为什么不通过向列添加表别名来解决它:
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/86293.html