以上都错误 你知道所有表中的name 举例 知道name 值是 a b c d
应该这么写看好咯
select t.* from 表1 t where t.name in ('a','b','c','d')
union all
select t2.* from 表2 t2 where t2.name in ('a','b','c','d')
union all
select t3.* from 表3 t3 where t3.name in ('a','b','c','d')
union all
select t4.* from 表4 t4 where t4.name in ('a','b','c','d')
上面查出的做为一张表 再group by 一下看看多少个重复 需要取哪些数据
select count(1) as 数量 ,t5.id , t5.name from
(
select t.* from 表1 t where t.name in ('a','b','c','d')
union all
select t2.* from 表2 t2 where t2.name in ('a','b','c','d')
union all
select t3.* from 表3 t3 where t3.name in ('a','b','c','d')
union all
select t4.* from 表4 t4 where t4.name in ('a','b','c','d')
) group by t5.id , t5.name
楼主是想四个ID 平行显示吧,就是每一行有四个表的ID ,然后显示所有?这样看看可以不?
SELECT
(select id from table1) name1,
(select id from table2) name2,
(select id from table3) name3,
(select id from table4) name4
from dual;
搞定了,这样就可以了
SELECT
(select name1 from table1 where id1 = '1') name1,
(select name2 from table2 where id2 = '2') name2,
(select name3 from table3 where id3 = '3') name3
from dual;
select id from tab1 where name='name1'
union all
select id from tab2 where name='name2'
union all
select id from tab3 where name='name3'
union all
select id from tab4 where name='name4'
;