我有5个表,比如t1,t2,t3,t4,t5。所有这些表都有相同的列名,即“#NAME'”。现在为每个表' NAME'列是唯一的,但可以在两个或两个以上的表上重复。我想找到常见的名字'以及他们在哪些桌子上。 在UNION ALL之后,我得到了这样的Image after doing UNION ALL
结果应显示' sona'和&#s; sonali'以及这些值存在的表格
答案 0 :(得分:0)
试试这个
select 1
from (
select name as name from tbl1
union all
select name from tbl2
union all
select name from tbl3
union all
select name from tbl4
union all
select name from tbl5
) a
where name = 'someuser'
答案 1 :(得分:0)
"SELECT t1.NAME, '' AS 'TABLE' FROM (select NAME from client1 UNION ALL select NAME from client2 UNION ALL select NAME from client3 "
"UNION ALL select NAME from client4 UNION ALL select NAME from client5) t1 "
" WHERE (select count(*) FROM (select NAME from client1 UNION ALL select NAME from client2 UNION ALL select NAME from client3 "
"UNION ALL select NAME from client4 UNION ALL select NAME from client5) t2 WHERE t1.NAME=t2.NAME)>1 GROUP BY NAME ORDER BY NAME"
有了这个,我可以找到通用名称,但找不到它们属于哪个表。