日期:2014-05-17 浏览次数:20542 次
;with ta(GameID,GameName) as
(
select 1,'aaa'
union all select 2,'bbb'
union all select 3,'ccc'
),
tb(RoomID, GameID,RoomName) as
(
select 1,2,'ddd'
union all select 2,2,'ggg'
union all select 3,3,'fff'
union all select 4,1,'hhh'
union all select 5,3,'ttt'
)
select RoomID,a.GameName,b.RoomName
from tb b
left join ta a on b.GameID=a.GameID
/*
RoomID GameName RoomName
-------------------------------
1 bbb ddd
2 bbb ggg
3 ccc fff
4 aaa hhh
5 ccc ttt
*/
create table #ta(GameID int,GameName varchar(50))
insert into #ta
select 1,'aaa'
union all select 2,'bbb'
union all select 3,'ccc'
create table #tb(RoomID int, GameID int,RoomName varchar(50))
insert into #tb
select 1,2,'ddd'
union all select 2,2,'ggg'
union all select 3,3,'fff'
union all select 4,1,'hhh'
union all select 5,3,'ttt'
select RoomID,a.GameName,b.RoomName
from #tb b
left join #ta a on b.GameID=a.GameID
--------------------------RoomID GameName RoomName
----------- -------------------------------------------------- --------------------------------------------------
1 bbb &n