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

如何从总表里得到分表的信息

2012-02-25 
怎么从总表里得到分表的信息?现在有三个表table1idname...C101李华table2idname...C201陈明table_listidC1

怎么从总表里得到分表的信息?
现在有三个表

table1
id name ...
C101 李华

table2
id name ...
C201 陈明

table_list
id
C101
C201

我想通过table_list里的id 查询table1和table2的人名。


[解决办法]

SQL code
select t.id, t3.namefrom table_list tinner join (select id, name from table1union allselect id, name from table2) t3on t.id=t3.id
[解决办法]
如果还有的表与前两表并列,继续 union
引用一楼代码:
SQL code
select t.id, t3.namefrom table_list tinner join (select id, name from table1union allselect id, name from table2on t.id=t3.idunion allselect id,name from table3....) t3
[解决办法]
探讨

求更多提示。
最后传的语句好长。
晕,

引用:

如果有N个表 可以考虑用动态语句了。

热点排行