簡體   English   中英

sql從3個不同的表中提取相同的列

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

嗨,我有 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  
)

不確定,但我認為你在追求這樣的事情......

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