Using UNION, EXCEPT and INTERSECT with Other Transact-SQL Statements
Follow these guidelines when using UNION, EXCEPT and INTERSECT with other Transact-SQL statements:
-
The first query can contain an INTO clause that creates a table to hold the final result set. Only the first query can use an INTO clause. If the INTO clause appears anywhere else, SQL Server 2005 displays an error message.
-
ORDER BY is allowed only at the end of the statement. It cannot be used within the individual queries that make up the statement.
Note: Using one ORDER BY clause applies only to when using UNION, EXCEPT and INTERSECT in a top-level query and not in a subquery. -
GROUP BY and HAVING clauses can be used only within individual queries; they cannot be used to affect the final result set.
-
UNION, EXCEPT and INTERSECT can be used within an INSERT statement.
-
The FOR BROWSE clause cannot be used in statements that involve the UNION, EXCEPT and INTERSECT operators.
Concepts
Performing Semi-Joins with EXCEPT and INTERSECTOther Resources
SELECT (Transact-SQL)UNION (Transact-SQL)
EXCEPT and INTERSECT (Transact-SQL)