PrepAway - Latest Free Exam Questions & Answers

Which of the following Transact-SQL statements would return the required information?

You work as a database developer at ABC.com. ABC.com has a SQL Server 2012 database
named SalesDB as illustrated in the following database diagram:

ABC.com has retail stores in a few major cities across the country. The company wants a list of
Customers who live in a city that does not have a ABC.com store, along with the customer’s City.
The result set must be sorted alphabetically by City name.
Which of the following Transact-SQL statements would return the required information?

PrepAway - Latest Free Exam Questions & Answers

A.
SELECT CustomerName, CustomerCity
FROM Customers
WHERE CustomerCity NOT EXISTS (SELECT StoreCity FROM Stores)
ORDER BY CustomerCity

B.
SELECT CustomerName, CustomerCity
FROM Customers
WHERE CustomerCity < > ALL (SELECT StoreCity FROM Stores)
ORDER BY StoreCity

C.
SELECT CustomerName, CustomerCity
FROM Customers
WHERE CustomerCity < > ANY (SELECT StoreCity FROM Stores)
ORDER BY CustomerCity

D.
SELECT CustomerName, CustomerCity
FROM Customers
WHERE CustomerCity NOT IN (SELECT StoreCity FROM Stores)
ORDER BY StoreCity

Explanation:

11 Comments on “Which of the following Transact-SQL statements would return the required information?

  1. Mr Meat says:

    The answer is C. B and D are obviously invalid because they are ordering by the cities where stores exist. The object of this query is to obtain a sorted list of cities that do not have existing stores, therefore you must ORDER BY the cities of the Customer.




    0



    0
  2. Shoaib says:

    I agree to tomazzi there is no correct answer
    A- Syntax error
    B- would be correct option if sorting would be on CustomerCity. Otherwise error
    C- would return all cities either stores exists or not
    D- would be correct, if sorting would be on CustomerCity. Otherwise error




    0



    0

Leave a Reply