Interrogating with INTERSECT
INTERSECT
and EXCEPT
are very useful for data interrogation.
The Earthquakes
and NBA Season 2017-2018
databases both contain information on countries and cities. You are interested to know which countries are represented by players in the 2017-2018 NBA season and you believe you can get the results you require by querying the relevant tables across these two databases.
Use the INTERSECT
operator between queries, but be careful and think about the results. Although both tables contain a country name column to compare, these are separate databases and the data may be stored differently.
This exercise is part of the course
Improving Query Performance in SQL Server
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT CountryName
FROM ___ -- Table from Earthquakes database
___ -- Operator for the intersect between tables
SELECT Country
FROM ___; -- Table from NBA Season 2017-2018 database