|
create table A (id int, title nvarchar (10), user1 int, user2 int)
insert A select 1, 'Article 1', 1, 2
create table B (id int, username nvarchar (10))
insert B select 1, '张三'
union all select 2, '李四'
select A.id, A.title, tmpA.username as user1, tmpB.username as user2 from A
left join B as tmpA on A.user1 = tmpA.id
left join B as tmpB on A.user2 = tmpB.id
--result
id title user1 user2
----------- ---------- ---------- ----------
1 Article 1 Zhang San Li Si
(1 row (s) affected) |
|