0

这是我在下面给出的表格:

用户详细信息表:

userid      name
 1          A   
 2          B

日志表:

Id          requesterId         ApproveId
1               1                   2  

我正在尝试以下查询:

select * from userDetils.name as Requester,**(What i can do here to get approver name)**
from Logs
join userDetail on Logs.requesterId = userDetails.userid

问题 :

我如何获得请求者和批准者的姓名

作为

Requester   Approver
  A           B
4

2 回答 2

4
select 
requester.name as Requester,
approver.name as Approver
from Logs as l
join userDetail as requester on l.requesterId = requester.userid
join userDetail as approver on l.ApproveId = approver.userid
于 2013-06-27T09:54:17.833 回答
0
select requester.Name as Requester,
       approver.Name as Approver
from Logs log
join userDetail requester
on requester.userid = log.requesterId
join userDetail approver
on approver.userid = log.approverId

您可以使用不同的子句在同一个表上连接两次。

于 2013-06-27T09:54:26.917 回答