-- Write a query that returns -- countries where there are customers but not emp
ID: 3594753 • Letter: #
Question
-- Write a query that returns
-- countries where there are customers but not employees using EXIST. (instead of using IN)
-- Tables involved: TSQL2012 database, Customers and Employees tables
-sample query
SELECT DISTINCT country
FROM Sales.Customers
WHERE country NOT IN
(SELECT E.country FROM HR.Employees AS E);
-- Desired output:
country
---------------
Argentina
Austria
Belgium
Brazil
Canada
Denmark
Finland
France
Germany
Ireland
Italy
Mexico
Norway
Poland
Portugal
Spain
Sweden
Switzerland
Venezuela
(19 row(s) affected)
Explanation / Answer
Answer:
SELECT DISTINCT c.country
FROM Sales.Customers c
WHERE NOT EXISTS
(SELECT E.country FROM HR.Employees AS E where c.country = E.country);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.