Home > OS >  Combine 2 tables in mysql with different column names in MySQL
Combine 2 tables in mysql with different column names in MySQL

Time:12-22

I want to combine two tables in one query and don't know how to do it, for example:

Table 1

id description
1 description_1
2 description_2
3 description_3
4 description_4

Table 2

id material_name
5 material_name_1
6 material_name_2
7 material_name_3
8 material_name_4

ultimately the result of my query should look like this:

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

CodePudding user response:

You can use the union all operator:

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