首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

拼凑SQL语句

2012-06-21 
拼接SQL语句SQL codeselect ID,Name from Users as userleft join Admin as ad on user.Idad.Idselect ID

拼接SQL语句

SQL code
select ID,Name from Users as userleft join Admin as ad on user.Id=ad.Idselect ID,C_Name from Group as grouleft join Group as cg on grou.ID=cg.serial

上面有两SQL语句,下边是运行的结果,相同的是表1的ID跟表2的ID
ID Name
AU01 张一
AU02 张二

ID C_Name
AU01 组1
AU02 组2
现在我想把这两个给结合起来,显示AU01,张一,组1该怎么做,

[解决办法]
SQL code
select * from (    select ID,Name     from Users as user    left join Admin as ad on user.Id=ad.Id) a inner join (    select ID,C_Name     from Group as grou    left join Group as cg on grou.ID=cg.serial) on a.ID = b.ID
[解决办法]
SQL code
select * from (    select ID,Name     from Users as users    left join Admin as ad on users.Id=ad.Id) a inner join (    select ID,C_Name     from [Group] as g    left join [Group] as cg on g.ID=cg.serial) b on a.ID = b.ID 

热点排行