From the course: Querying Microsoft SQL Server 2019

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Return distinct rows with EXCEPT

Return distinct rows with EXCEPT - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2019

Start my 1-month free trial

Return distinct rows with EXCEPT

- [Instructor] Like UNION, the EXCEPT operator will merge two query result sets together. However, EXCEPT only returns distinct rows from the first query that aren't present in the second. Let's use this to help us identify all of the people that don't have credit cards on file with AdventureWorks. First, I'm going to write a couple of queries to get a sense of the raw data that we can work with. I'm going to select everything from the Person.Person table and select everything from the Sales.PersonCreditCard table. The Person table lists everyone in the database. Employees, customers, vendors, contractors, everyone. Employees are given the PersonType code of EM. So we might want to filter out the employees from the final query. The PersonCreditCard table which is right down here, we have the BusinessEntityID that links back to the Person table as well as the CreditCardID that links to the Sales.CreditCard table. We…

Contents