【问题标题】:sql to extract same columns from 3 different tablessql从3个不同的表中提取相同的列
【发布时间】:2016-09-27 17:01:27
【问题描述】:

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

【问题讨论】:

  • 您的查询甚至无法解析,您的语法错误。
  • 你使用的是MySQL还是SQL Server
  • 我正在使用 Netezza

标签: mysql sql sql-server select


【解决方案1】:

不确定,但我认为您正在追求这样的事情......

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

【讨论】:

    猜你喜欢
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 2012-03-12
    • 2019-09-11
    相关资源
    最近更新 更多