Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
7.4. Combining Queries
Prev UpChapter 7. QueriesHome Next

7.4. Combining Queries

The results of two queries can be combined using the set operations union, intersection, and difference. The syntax is

query1 UNION [ALL]query2query1 INTERSECT [ALL]query2query1 EXCEPT [ALL]query2

query1 andquery2 are queries that can use any of the features discussed up to this point. Set operations can also be nested and chained, for example

query1 UNIONquery2 UNIONquery3

which is executed as:

(query1 UNIONquery2) UNIONquery3

UNION effectively appends the result ofquery2 to the result ofquery1 (although there is no guarantee that this is the order in which the rows are actually returned). Furthermore, it eliminates duplicate rows from its result, in the same way asDISTINCT, unlessUNION ALL is used.

INTERSECT returns all rows that are both in the result ofquery1 and in the result ofquery2. Duplicate rows are eliminated unlessINTERSECT ALL is used.

EXCEPT returns all rows that are in the result ofquery1 but not in the result ofquery2. (This is sometimes called thedifference between two queries.) Again, duplicates are eliminated unlessEXCEPT ALL is used.

In order to calculate the union, intersection, or difference of two queries, the two queries must beunion compatible, which means that they return the same number of columns and the corresponding columns have compatible data types, as described inSection 10.5.


Prev Up Next
7.3. Select Lists Home 7.5. Sorting Rows
pdfepub
Go to Postgres Pro Standard 9.5
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp