我有一个表格Users
,它连接多次,如下所示:
所以,当我向用户请求Name
Request
时,我会得到一个名字,我想要两个,这是我第一次遇到这种情况,我不知道如何从SQL做到这一点。
查询可能如下:
SELECT Name as Originator, Name as Requestee FROM View ... JOIN ... WHERE Id = 123
答案 0 :(得分:5)
很简单,你需要两个用户,你加入Users
表两次,如:
SELECT ou.Name as Originator, ru.Name as Requestee
FROM Requests r
INNER JOIN Users ou ON r.Originator_Id = ou.Id
INNER JOIN Users ru ON r.Requestee_Id = ru.Id
WHERE r.Id = 123