Query two tables, then print them in one column

I want to query two tables and then give the result in one column, like

table1 id name town 23 john nyc 34 mark ATl 44 ali Dubs table2 cno reg 45 kln 47 dsgd 28 wer 

the conclusion that I expect

 newcolumn 23 34 44 45 47 28 
+5
source share
1 answer

You need to use MySQL UNION .

 SELECT id FROM table 1 UNION SELECT cno AS id FROM table2 

In UNION you can combine results from two or more database tables.

But for this, the selected columns should be similar.

For example, if you extract 5 fields from one SQL and 6 fields from another SQL.

And making UNION from these two queries, this will not work.

The above SQL works because you select one column from SQL.

+5
source

Source: https://habr.com/ru/post/1234778/


All Articles