Databases Querying Relational Databases Set Operations Union All Operations

Sean Flanagan
Sean Flanagan
33,225 Points

Task 2

Hi. I used the EXCEPT operator for this task but I couldn't exclude books that were in both tables.

-- Create a list of unique books. 
-- Books that are in the north or south location, but not in both locations.

SELECT * FROM books_north
SELECT * FROM books_south

Am I doing something wrong?

Rich Donnellan
Rich Donnellan
Treehouse Moderator 25,740 Points

Hey Sean,

I suggest rewatching the videos (maybe multiple times?) until the concept starts to click. Posting back-to-back questions on the same topic should be a last resort.

1 Answer

Mustafa Başaran
Mustafa Başaran
28,020 Points

<Query1> EXCEPT <Query2> returns all rows in Query1 that are NOT retrieved in Query2. This is NOT going to return unique books.

On the other hand, <Query1> UNION <Query2> will get ALL rows in Query1 and Query2. Moreover, there will be no DUPLICATE rows.. So, the returned rows will be UNIQUE.