-2

大家好,我正在尝试根据找到的数据从三个不同的表中选择数据。它不工作。我正在尝试在网格视图中显示所选内容。有任何想法吗?

 SELECT BossID, Status, CouponNumber, FK_PrizeID, FK_WinnerID 
 FROM BountyPrizes 
 union  
 select PrizeName from Prizes where PrizeID=FK_PrizeID  
 union  
 select FirstName, LastName, DOB from Players where PlayerID=FK_WinnerID

错误:消息 207,级别 16,状态 1,第 6 行无效的列名称“FK_PrizeID”。消息 207,级别 16,状态 1,第 8 行无效的列名称“FK_WinnerID”。

4

4 回答 4

2

联接是您希望从其他表中获取更多信息的地方。联合是您想要获取 2 个全等表并显示组合结果的地方

这是您需要的代码:

SELECT BossID, Status, CouponNumber, FK_PrizeID, FK_WinnerID 
FROM BountyPrizes  
JOIN Prizes ON PrizeID=FK_PrizeID  
JOIN Players ON PlayerID=FK_WinnerID
于 2013-08-09T18:48:04.637 回答
0
SELECT BossID, Status, CouponNumber, FK_PrizeID, FK_WinnerID, PrizeName, 
  FirstName, LastName, DOB 
FROM BountyPrizes, Prizes, Players
WHERE Prizes.PrizeID=BountyPrizes.FK_PrizeID 
  AND Players.PlayerID=BountyPrizes.FK_WinnerID
于 2013-08-09T18:46:49.317 回答
0

我认为你需要加入:

SELECT T1.BossID, 
       T1.Status, 
       T1.CouponNumber, 
       T1.FK_PrizeID, 
       T1.FK_WinnerID,
       T2.PrizeName ,
       T3.FirstName, 
       T3.LastName, 
       T3.DOB
FROM   BountyPrizes T1
       LEFT JOIN Prizes T2
           ON T2.PrizeID=T1.FK_PrizeID
       LEFT JOIN Players T3
           ON T3.PlayerID=T1.FK_WinnerID
于 2013-08-09T18:46:49.770 回答
0

尝试这个:

SELECT BossID, Status, CouponNumber, FK_PrizeID, FK_WinnerID, Prizes.*, Players.*
FROM BountyPrizes 
JOIN Prizes on PrizeID=FK_PrizeID  
JOIN Players on PlayerID=FK_WinnerID
于 2013-08-09T18:46:55.000 回答