IniziaInizia gratis

IN and EXISTS

You want to know which, if any, country capitals are listed as the nearest city to recorded earthquakes. You can get this information using INTERSECT and comparing the Nations table with the Earthquakes table. However, INTERSECT requires that the number and order of columns in the SELECT statements must be the same between queries and you would like to include additional columns from the outer query in the results.

You attempt two queries, each with a different operator that gives you the results you require.

Questo esercizio fa parte del corso

Improving Query Performance in SQL Server

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

-- First attempt
SELECT CountryName,
       ___, -- 2017 country population
	   ___, -- Capital city	   
       WorldBankRegion
FROM Nations
WHERE Capital ___ -- Add the operator to compare queries
        (SELECT NearestPop 
	     FROM Earthquakes);
Modifica ed esegui il codice