我需要幫助建立此查詢,我需要從同一表中選擇不同的值,但不同的唯一鍵。SQL查詢 - 多個連接在同一字段
更詳細地說明病人提供下面的例子:
我有2個表:
問題(IssueID,AuthorID_FK,AssigedID_FK,...)
用戶(用戶ID,User_Label,.. 。)
兩個AuthorID_FK & AssigedID_FK AR e鏈接到表用戶和我需要得到相同的查詢結果User_Label兩者。
您能否協助?
感謝,
我需要幫助建立此查詢,我需要從同一表中選擇不同的值,但不同的唯一鍵。SQL查詢 - 多個連接在同一字段
更詳細地說明病人提供下面的例子:
我有2個表:
問題(IssueID,AuthorID_FK,AssigedID_FK,...)
用戶(用戶ID,User_Label,.. 。)
兩個AuthorID_FK & AssigedID_FK AR e鏈接到表用戶和我需要得到相同的查詢結果User_Label兩者。
您能否協助?
感謝,
SELECT a.IssueID, b.User_Label, c.User_Label FROM Issues a
INNER JOIN USERS b on a.AuthorID_FK = b.UserID
INNER JOIN USERS c on a.AssignedID_FK = c.UserID
類似的東西:)這應該在MS SQL服務器
很好地工作,這應該工作太:)
SELECT IssueID, U.User_Label FROM Issues I
INNER JOIN Users U ON U.UserID = I.AuthorID_FK
UNION
SELECT IssueID, U.User_Label FROM Issues I
INNER JOIN Users U ON U.UserID = I.AssigedID_FK
慣於
SELECT a.IssueID, b.UserID
FROM Issues a
JOIN Users b ON (a.AuthorID_FK=b.UserID OR a.AssignedID_FK = b.UserID)
工作?
你可能想嘗試這樣的事情
SELECT
issues.IssueID,
Authour.User_Label AS Author_Label,
Assigned.User_Label AS Assigned_user_Label
FROM
issues
INNER JOIN users AS Authour ON Authour.UserID = issues.AuthorID_FK
INNER JOIN users AS Assigned ON Assigned.UserID = issues.AssignedID_FK
這將是有益的,如果你顯示你預期的結果.. – 2012-04-10 09:20:33