第六章 使用集合

1.基本描述

    本章主要讲解如何使用各种集合操作符来联合多个表。通常将联接操作看作是表之间的水平操作,因为该操作生成的虚拟表包含两个表中的列。

2.基本样例

DESC product;

DESC customer;

SELECT 1 num, 'abc' str
UNION 
SELECT 9 num, 'xyz' str;

SELECT 'IND' type_cd, cust_id, lname name
FROM individual
UNION ALL
SELECT 'BUS' type_cd, cust_id, name
FROM business;

SELECT 'IND' type_cd, cust_id, lname name
FROM individual
UNION ALL
SELECT 'BUS' type_cd, cust_id, name
FROM business
UNION ALL
SELECT 'BUS' type_cd, cust_id, name
FROM business;

SELECT emp_id
FROM employee
WHERE assigned_branch_id = 2
AND (title = 'Teller' OR title = 'Head Teller')
UNION ALL
SELECT DISTINCT open_emp_id
FROM account
WHERE open_branch_id = 2;
上一篇:MySQL视图和存储过程


下一篇:MB51 选择屏幕增加字段