OlegB
OlegB

Reputation: 71

Combine 2 tables in mysql with different column names in MySQL

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

Upvotes: 3

Views: 170

Answers (1)

Mureinik
Mureinik

Reputation: 311228

You can use the union all operator:

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

Upvotes: 1

Related Questions