Which Transact-SQL query should you use?

You have 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 include customers who have not placed any orders.
Which Transact-SQL query should you use?

You have 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 include customers who have not placed any orders.
Which Transact-SQL query should you use?

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

B.
SELECT CustomerName, CrderDate
FROM Customers
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
LEFT OUTER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID

Explanation:
http://msdn.microsoft.com/en-us/library/ms177634.aspx



Leave a Reply 4

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


Bob

Bob

D.
LEFT OUTER JOIN – Specifies that all rows from the left table not meeting the join condition are included in the result set, and output columns from the other table are set to NULL in addition to all rows returned by the inner join.

salim

salim

D . SELECT CUSTOMERNAME,ORDERDATE
FROM CUSTOMERS LEFT OUTER JOIN ORDERS ON CUSTOMERID=CUSTOMERID

–This will get list of all the customers and also the ordersdate