Set Operators

Use Set Operators to combine rows from several tables into a single results.

Throughout this blog we have written articles to show you how to combine rows from tables using operators.  These are UNION, INTERSECTION, and EXCLUDE.

If you are not familiar with how to use set operators, I would start with the article Learn to use Union, Intersect, and Except Clauses.

One of our most popular article looks at the difference between a Join and UNION.  This is something people often confuse, so it is worth a read!

All the examples for this lesson are based on Microsoft SQL Server Management Studio.  They use the sample databases AdventureWorks and WideWorldImporters.  You can get started using these free tools using my guide Getting Started Using SQL Server

Latest Posts

  • Is it possible to use Joins, Subqueries, and Unions on Multiple Tables?
    , ,

    ·

    Is it possible to use Joins, Subqueries, and Unions on Multiple Tables?

    A reader recently asked me to help them solve a problem combining data from multiple tables into a single result.  What was interesting was that the solution used the three ways to combine data that we have recently covered, namely:  joins, set operators, and subqueries. Given the comprehensive nature of this problem I thought it…

  • How do I combine results from several SQL tables (hint: there are three ways)
    , , ,

    ·

    How do I combine results from several SQL tables (hint: there are three ways)

    Many times in a relational database the information you want to show in your query is in more than one table.  This begs the question “How do you combine results from more than one table?” All the examples for this lesson are based on Microsoft SQL Server Management Studio and the AdventureWorks2012 database.  You can…

  • What Is the Difference Between a Join and a UNION?
    , ,

    ·

    What Is the Difference Between a Join and a UNION?

    Use joins and UNIONS to combine data from two or more tables.  Read this article to find out each command’s strengths and when to use them. To get the most of this and our other lessons are sure to practice using the examples! All the examples for this lesson are based on Microsoft SQL Server…

  • SQL Union, Intersect, and Except – The Ultimate Guide

    ·

    SQL Union, Intersect, and Except – The Ultimate Guide

    The SQL UNION, SQL INTERSECT, and SQL EXCEPT clauses are used to combine or exclude like rows from two or more tables.  They are useful when you need to combine the results from separate queries into one single result.  They differ from a join in that entire rows are matched and, as a result, included…

  • Full Outer Join as Union
    , ,

    ·

    Full Outer Join as Union

    In this puzzle, we’re going to learn how to write a SQL UNION without using Set Operations.  Set operations allow us to compare rows from two or more tables to arrive at a result.   For several classes of problems, it is much easier to use a set operation, than join data.  But can we do…

  • SQL Set Operators
    ,

    ·

    SQL Set Operators

    In this puzzle, we’re going learn to about SQL set operators.  Set operators allow us to compare rows from two or more tables to arrive at a result.   For several classes of problems, is is much easier to use a set operation, than join data. Solving puzzles is a great way to learn SQL.  Nothing…