select a.id,a.name,b.name from tb a ,tb b where a.uid=b.id
declare @t table (id int,name varchar(4),u_id int) insert into @t select 1,'张三',2 union all select 2,'李四',3 union all select 3,'王五',1select a.id,a.name,b.name from @t a LEFT JOIN @t b ON a.u_id=b.id /* id name name ----------- ---- ---- 1 张三 李四 2 李四 王五 3 王五 张三 */
select a.id,a.name,b.name from tb a ,tb b where a.uid=b.id
declare @t table (id int,name varchar(4),u_id int)
insert into @t
select 1,'张三',2 union all
select 2,'李四',3 union all
select 3,'王五',1select a.id,a.name,b.name
from @t a LEFT JOIN @t b ON a.u_id=b.id
/*
id name name
----------- ---- ----
1 张三 李四
2 李四 王五
3 王五 张三
*/