sql查询一个表中的两个字段从表中连接一个字段

时间:2009-11-08 06:09:08

标签: sql-server

我有两张桌子:

users(userid, username)

cases(cid,assign_to,received_by)

我想加入assign_to和  received_by user_id并生成username username

我如何加入这些表格以及我如何加入  生成assign_toreceived_by和  assign_to

这两个字段received_byuserid存储不同  > eg assign_to received_by > 1 3 > 2 4

username

我想在这些字段中生成{{1}}。

1 个答案:

答案 0 :(得分:2)


select u1.* from Users as u1
join Cases as c1
on u1.userid = c1.received_by
join cases as c2
on u1.userid = c2.assign_to


以下是此目的的基本联接