Home > database >  All of the mysql connection problem, union all
All of the mysql connection problem, union all

Time:09-27

The original data table:

Want to get the results of the

Everyone a great god, and I use the mysql database, do a full connection, according to the t_day, t_kind 5 and 6 have empty, my SQL is as follows:
The SELECT A.a kind, A.a num, B.b num
The FROM
(SELECT t_kind AS akind, t_num AS anum FROM test_table WHERE t_day='1') AS A
UNION ALL
(SELECT t_kind AS bkind, t_num AS bnum FROM test_table WHERE t_day='2') AS B
ON A.a kind=B.b kind
Change the red part to left the join and right join can be executed correctly, but not for whole connection
Look at the trouble to get the results of figure 2, how to write SQL should thank