About the structure of the same multi-table merger
In fact, this problem is very simple.
Two Test1 and Test2 (the structure of two tables) TEST1 data is as follows: - -------- | A | B | - ------ - | 1 | 1 || 2 | 2 || 3 | 3 | - --------
TEST2 data is as follows: - -------- | A | B | - -------- | 1 | 4 || 2 | 5 | - - --------
How to get the following data - ------ -------- | 1 | 1 | A | B | - -------- | 1 | 1 | | 2 | 2 || 3 | 3 || 1 | 4 || 2 | 5 | - --------
You can use the Select * from test1 union select * from test2 to implement
At the same time, you can also specify query conditions for each table, as follows: Select * from test1 where a = 3 Union Select * from test2 where a = 2
The results are as follows: - -------- | A | B | - -------- | 3 | 3 || 2 | 5 | - - --------
There is also a matter of attention, the number of fields and types of all tables must be the same, if you cannot use the following SQLSELECT A from Test1 Union Select 2 (the number of fields does not match)