简体   繁体   English

sql从3个不同的表中提取相同的列

[英]sql to extract same columns from 3 different tables

Hi i have 3 tables i want to extract same columns from 3 tables is this better way to write Select query.嗨,我有 3 个表,我想从 3 个表中提取相同的列,这是编写 Select 查询的更好方法。

select * from 
(
select col1,
select id1 from testid1 where name=pnrtable1.name,
col3 from table1  
union all  
select coltab1,
select newid2 from testid2 where name=pnrtable2.name,
coltab3 from table2  
union all  
select namecol1,
select id3 from testid3 where name=pnrtable3.name,
namecol3 from table3  
)

Not sure but I think you are after something like this....不确定,但我认为你在追求这样的事情......

select * from 
(
select t1.col1, t2.id1 , t1.col3 from table1  t1 
                                 INNER JOIN testid1 t2 ON t1.name = t2.name
union all  
select t1.coltab1, t2.newid2, t1.coltab3 from testid2 t1 
                                         INNER JOIN table2 t2 ON t1.name=t2.name
union all  
select t1.namecol1, t2.id3, t1.namecol3 from testid3 t1 
                                       INNER JOIN table3 t2 ON t1.name=t2.name
) A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM