Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:52:46+00:00 2026-05-28T22:52:46+00:00

I was just reading about EXCEPT and INTERSECT in the MSDN Library and came

  • 0

I was just reading about EXCEPT and INTERSECT in the MSDN Library and came across this example of how to use INTERSECT:

USE AdventureWorks2008R2 GO 
SELECT ProductID 
FROM Production.Product
INTERSECT
SELECT ProductID 
FROM Production.WorkOrder ;
--Result: 238 Rows (products that have work orders)

Maybe I’m old-fashioned, but I typically would use the following code to achieve the same result:

SELECT P.ProductID 
FROM Production.Product P 
INNER JOIN Production.WorkOrder W ON W.ProductID = P.ProductID

Am I missing something, or is INTERSECT the same as INNER JOIN? Is there a performance benefit to using one over the other?

Same question for EXCEPT. How is this:

USE AdventureWorks2008R2;
GO
SELECT ProductID 
FROM Production.Product
EXCEPT
SELECT ProductID 
FROM Production.WorkOrder ;
--Result: 266 Rows (products without work orders)

different from this:

SELECT P.ProductID 
FROM Production.Product P 
LEFT JOIN Production.WorkOrder W ON W.ProductID = P.ProductID
WHERE W.ProductID IS NULL

?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:52:46+00:00Added an answer on May 28, 2026 at 10:52 pm

    I’m going to focus on EXCEPT just because I’m more familiar with it. Also, as a disclaimer, my examples will be in Sqlite, since I’m on a Linux box. However, both Sqlite and SQL Server should support the functionality.

    Both INTERSECT and EXCEPT are set operators, stemming from the underlying ideas in relational algebra. They operate on distinct values, being set operators.

    Your example is simplistic. I’ll give a counterexample, using a Sqlite version of the Northwind sample database.

    Let’s say that you want to get the CustomerIDs of all customers who made an order with EmployeeID of 5, but NOT those who also made an order with EmployeeID of 6. This is simple and natural with an EXCEPT.

    SELECT CustomerID FROM orders
    WHERE EmployeeID = 5
    EXCEPT
    SELECT CustomerID FROM orders
    WHERE EmployeeID = 6
    

    This returns 14 rows on my version of Northwind.

    Suppose you decide to rewrite this using JOINs. Maybe something like this?

    SELECT o1.CustomerID
    FROM orders o1 INNER JOIN orders o2 ON o1.CustomerID = o2.CustomerID
    WHERE o1.EmployeeID = 5 AND o2.EmployeeID != 6
    

    Whoops, 525 rows. Maybe add a DISTINCT?

    SELECT DISTINCT o1.CustomerID
    FROM orders o1 INNER JOIN orders o2 ON o1.CustomerID = o2.CustomerID
    WHERE o1.EmployeeID = 5 AND o2.EmployeeID != 6
    

    Now it’s 28 rows, still much more than what we were getting with EXCEPT. The reason is that this isn’t removing CustomerIDs that have made an order with 6. Rather, it returns all CustomerIDs that have an order with 5 and some EmployeeID other than 6, whether or not they also have an order with EmployeeID 6.

    In short, EXCEPT and INTERSECT are set operators that compare two queries, returning unique tuples, and certainly have their use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just reading about Gems/Plugin development for Rails 3 and ran across this
I was just reading the http://www.meebo.com/ About Us page, and read this line :
I'm just reading about malloc() in C. The Wikipedia article provides an example ,
I was just reading about Magento , a free framework for easily creating an
I just finished reading about scoping in the R intro , and am very
I just starting reading about SEO and realized that I should change my GET
I was just reading abit about JMS and Apache ActiveMQ. And was wondering what
I've just been reading about MSDeploy, the new website deployment tool from Microsoft. I'm
We have a bunch of data on S3 (images) but just started reading about
I just began reading more about Markov Chain Generators today, and am really intrigued

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.