Tip of the Day : Transact-SQL Set Operators (UNION, EXCEPT and INTERSECT)

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - July 10, 2025

Transact-SQL Set Operators (UNION, EXCEPT and INTERSECT)

Set operators combine results from two or more queries into a single result set. There are 3 Transact-SQL set operators available in SQL Server namely, UNION, EXCEPT and INTERSECT. The following are basic rules for combining the result sets of two queries by using the UNION, EXCEPT and INTERSECT set operators:

  • The number and the order of the columns must be the same in all queries.
  • The data types must be compatible.

The UNION set operator combines the results of two or more queries into a single result set that includes all the rows that belong to all queries in the union. The UNION set operator is different from using joins that combine columns from two tables.

The EXCEPT set operator returns any distinct values from the left query that are not also found on the right query.

The INTERSECT set operator returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand.

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions