第六章 使用集合

1. 基本描述spa

  本章主要講解如何使用各類集合操做符來聯合多個表。一般將聯接操做看做是表之間的水平操做,由於該操做生成的虛擬表包含兩個表中的列。code

2. 基本樣例blog

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;
相關文章
相關標籤/搜索