现在有三个表
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
------解决方案--------------------