- 表具体说明
- Impala - 创建表语句
- Impala - 插入语句
- Impala - 选择语句
- Impala - 描述语句
- Impala - 更改表
- Impala - 删除一个表
- Impala - 截断表
- Impala - 显示表
- Impala - 创建视图
- Impala - 改变视图
- Impala - 放下视图
- Impala - 条款
- Impala - 按条款排序
- Impala - Group By 子句
- Impala - 拥有子句
- Impala - 限制条款
- Impala - 抵消条款
- Impala - 联合条款
- Impala - 带子句
- Impala - 独特的运算符
- 黑斑羚有用的资源
- Impala - 快速指南
- Impala - 有用的资源
- Impala - 讨论
Impala - 联合条款
您可以使用 Impala 的Union子句组合两个查询的结果。
句法
以下是 Impala 中Union子句的语法。
query1 union query2;
例子
假设数据库my_db中有一个名为customer的表,其内容如下 -
[quickstart.cloudera:21000] > select * from customers; Query: select * from customers +----+----------+-----+-----------+--------+ | id | name | age | address | salary | +----+----------+-----+-----------+--------+ | 1 | Ramesh | 32 | Ahmedabad | 20000 | | 9 | robert | 23 | banglore | 28000 | | 2 | Khilan | 25 | Delhi | 15000 | | 4 | Chaitali | 25 | Mumbai | 35000 | | 7 | ram | 25 | chennai | 23000 | | 6 | Komal | 22 | MP | 32000 | | 8 | ram | 22 | vizag | 31000 | | 5 | Hardik | 27 | Bhopal | 40000 | | 3 | kaushik | 23 | Kota | 30000 | +----+----------+-----+-----------+--------+ Fetched 9 row(s) in 0.59s
同样,假设我们有另一个表名为employee,其内容如下:
[quickstart.cloudera:21000] > select * from employee; Query: select * from employee +----+---------+-----+---------+--------+ | id | name | age | address | salary | +----+---------+-----+---------+--------+ | 3 | mahesh | 54 | Chennai | 55000 | | 2 | ramesh | 44 | Chennai | 50000 | | 4 | Rupesh | 64 | Delhi | 60000 | | 1 | subhash | 34 | Delhi | 40000 | +----+---------+-----+---------+--------+ Fetched 4 row(s) in 0.59s
以下是 Impala 中union子句的示例。在此示例中,我们按照 id 的顺序排列两个表中的记录,并使用两个单独的查询并使用 UNION 子句连接这些查询,将记录数量限制为3。
[quickstart.cloudera:21000] > select * from customers order by id limit 3 union select * from employee order by id limit 3;
执行时,上述查询给出以下输出。
Query: select * from customers order by id limit 3 union select * from employee order by id limit 3 +----+---------+-----+-----------+--------+ | id | name | age | address | salary | +----+---------+-----+-----------+--------+ | 2 | Khilan | 25 | Delhi | 15000 | | 3 | mahesh | 54 | Chennai | 55000 | | 1 | subhash | 34 | Delhi | 40000 | | 2 | ramesh | 44 | Chennai | 50000 | | 3 | kaushik | 23 | Kota | 30000 | | 1 | Ramesh | 32 | Ahmedabad | 20000 | +----+---------+-----+-----------+--------+ Fetched 6 row(s) in 3.11s