程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> SQL 查詢中的並(Union)、交(Intersect)、差(Minus)

SQL 查詢中的並(Union)、交(Intersect)、差(Minus)

編輯:關於SqlServer

在數據庫的數據集操作中經常碰到大量的數據進行集合操作,這裡面有幾個比較重要的集合操作,對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) 



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved