什麼是我需要實現下面給出這兩個表中的結果MySQL的:MySQL的真行合併......不只是一個工會
表1:
+----+-------+
| id | name |
+----+-------+
| 1 | alan |
| 2 | bob |
| 3 | dave |
+----+-------+
表2:
+----+---------+
| id | state |
+----+---------+
| 2 | MI |
| 3 | WV |
| 4 | FL |
+----+---------+
我想創建一個看起來像這樣的臨時視圖
想要的結果:
+----+---------+---------+
| id | name | state |
+----+---------+---------+
| 1 | alan | |
| 2 | bob | MI |
| 3 | dave | WV |
| 4 | | FL |
+----+---------+---------+
我試過一個mysql聯盟,但以下結果不是我想要的。
create view table3 as
(select id,name,"" as state from table1)
union
(select id,"" as name,state from table2)
表3聯合的結果:
+----+---------+---------+
| id | name | state |
+----+---------+---------+
| 1 | alan | |
| 2 | bob | |
| 3 | dave | |
| 2 | | MI |
| 3 | | WV |
| 4 | | FL |
+----+---------+---------+
很好的示範和定義問題+1的 – SaidbakR