在數據庫的數據集操作中經常碰到大量的數據進行集合操作,這裡面有幾個比較重要的集合操作,對SQL的性能有較大的幫助。下面就是這幾個操作語句的介紹。
UNION Statement
Combine data from one or more SELECT statements.
In Oracle 8i (and above) the UNION command has been largely replaced by the new Analytic Features
Syntax:
SELECT command {UNION | UNION ALL | INTERSECT | MINUS} SELECT command
key:
UNION - Combine the unique rows returned by 2 SELECT statements
UNION ALL - Combine the rows returned by 2 SELECT statements (including all duplicates)
INTERSECT - Return only those rows that are in *both* SELECT statements
MINUS - Return the rows that are in the first SELECT but not the second
To combine more than two SELECTs simply nest the expressions
SELECT expr1 UNION (SELECT expr2 UNION SELECT expr3)