Java教程

合并查询

本文主要是介绍合并查询,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
 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 +-------------+

 

这篇关于合并查询的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!