【问题标题】:Combine 2 tables in mysql with different column names in MySQL将mysql中的2个表与MySQL中的不同列名组合起来
【发布时间】:2022-01-22 23:10:52
【问题描述】:

我想在一个查询中合并两张表,不知道怎么做,例如:

表 1

id description
1 description_1
2 description_2
3 description_3
4 description_4

表 2

id material_name
5 material_name_1
6 material_name_2
7 material_name_3
8 material_name_4

我的查询结果最终应该是这样的:

id description
1 description_1
2 description_2
3 description_3
4 description_4
5 material_name_1
6 material_name_2
7 material_name_3
8 material_name_4

【问题讨论】:

    标签: mysql select


    【解决方案1】:

    您可以使用union all 运算符:

    SELECT id, description
    FROM   table1
    UNION ALL
    SELECT id, material_name
    FROM   table2
    

    【讨论】:

    • Tnx,帮了大忙
    猜你喜欢
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多