class_A 資料表
s_id | name | gender | age
------------- | -------------
1 | Amy | female | 18
2 | John | male | 54
3 | David | male | 32
4 | Joyce | female |44
5 | Joe | male | 10
6 | Iris | female | 10
class_B 資料表
s_id | name | gender | age
------------- | -------------
1 | Cindy | female | 11
2 | Jack | male | 5
3 | John | male | 12
4 | Alice | female | 33
5 | Joe | male | 49
select name as students from class_A
union
select name from class_B
結果:
students |
---|
Amy |
John |
David |
Joyce |
Joe |
Iris |
Cindy |
Jack |
Alice |
Union會把重複的record去除,而Union all則是將所有資料保留下來
select name as students from class_A
union
select name from class_B
結果:
students |
---|
Amy |
John |
David |
Joyce |
Joe |
Iris |
Cindy |
Jack |
John |
Alice |
Joe |