Which Transact-SQL query should you use?

You develop a Microsoft SQL Server 2012 database that contains tables named Customers and Orders. The
tables are related by a column named CustomerId . You need to create a query that meets the following
requirements:
Returns the CustomerName for all customers and the OrderDate for any orders that they have placed.
Results must not include customers who have not placed any orders.
Which Transact-SQL query should you use?

You develop a Microsoft SQL Server 2012 database that contains tables named Customers and Orders. The
tables are related by a column named CustomerId . You need to create a query that meets the following
requirements:
Returns the CustomerName for all customers and the OrderDate for any orders that they have placed.
Results must not include customers who have not placed any orders.
Which Transact-SQL query should you use?

A.
SELECT CustomerName, OrderDate
FROM Customers
LEFT OUTER JOIN Orders
ON Customers.CuscomerlD = Orders.CustomerId

B.
SELECT CustomerName, OrderDate
FROM Customers
RIGHT OUTER JOIN Orders
ON Customers.CustomerID = Orders.CustomerId

C.
SELECT CustomerName, OrderDate
FROM Customers
CROSS JOIN Orders
ON Customers.CustomerId = Orders.CustomerId

D.
SELECT CustomerName, OrderDate
FROM Customers
JOIN Orders
ON Customers.CustomerId = Orders.CustomerId

Explanation:
Verified answer as correct.
Reference: http://msdn.microsoft.com/en-us/library/ms177634.aspx



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Frank Hyatt

Frank Hyatt

D is right but B is awfully attractive. On a theoretical level you can have orders with no customers, but practically speaking this shoulnd’t happen and b would be the same as d. D is certainly correct. B ought to be correct.