【问题标题】:Is it possible to make query with join and union?是否可以使用join和union进行查询?
【发布时间】:2016-03-18 10:15:06
【问题描述】:

我想做这样的查询...

select table1.col1, table1.col2, table1.col3 from table1 union
select table2col1, table1col2, table2col3 from table2
left join table2 on table1.col1 = table2.col1

我想要 table2 中 table1 中的一些列,因为我知道在 table2 中缺少一些列,我需要从 table1 来完成我使用加入的联合标准,但我也想要两个表的联合

任何建议都将不胜感激。

【问题讨论】:

    标签: mysql


    【解决方案1】:

    试试这个:

    (select table1.col1, table1.col2, table1.col3 from table1 )
    union
    (select table2col1, table1col2, table2col3 from table2
    left join table1 on table1.col1 = table2.col1)
    

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 2023-03-29
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多