其他分享
首页 > 其他分享> > 合并查询

合并查询

作者:互联网

 1 -- 示例
 2 +----------------+
 3  | E_ID | E_Name |
 4 +----------------+
 5  | 01|Zhang, Hua|
 6  |02 |Wang, Wei|
 7  |03 |Carter, Thomas|
 8  |04 |Yang, Ming|
 9 +-------------+-
10 |E_ID|  E_Name|
11 +-------------+-
12 |01    |Adams, John|
13 |02    |Bush, George|
14 |03    |Carter,Thomas|
15 |04    |Gates, Bill|
16 +-------------+-
17 
18 -- UNION  查出来会去除两个表重复的值
19 SELECT column_name(s) FROM table_name1
20 UNION
21 SELECT column_name(s) FROM table_name2
22 
23 --示例
24 SELECT E_Name FROM Employees_China
25 UNION
26 SELECT E_Name FROM Employees_USA
27 +-------------+
28 |E_Name|
29 +-------------+
30 |Zhang, Hua|
31 |Wang, Wei|
32 |Carter, Thomas|
33 |Yang, Ming|
34 |Adams, John|
35 |Bush, George|
36 |Gates, Bill|
37 +-------------+
38 
39 -- UNION ALL 查询出来 会包含两个表重复的数据
40 SELECT column_name(s) FROM table_name1
41 UNION ALL
42 SELECT column_name(s) FROM table_name2
43 
44 --示例
45 SELECT E_Name FROM Employees_China
46 UNION ALL
47 SELECT E_Name FROM Employees_USA
48 +-------------+
49 |E_Name|
50 +-------------+
51 |Zhang, Hua|
52 |Wang, Wei|
53 |Carter, Thomas|
54 |Yang, Ming|
55 |Adams, John|
56 |Bush, George|
57 |Carter, Thomas|
58 |Gates, Bill|
59 +-------------+

 

标签:Thomas,Name,UNION,合并,查询,--,+-------------+,SELECT
来源: https://www.cnblogs.com/chendakeng/p/15978820.html