Which Transact-SQL statement should you run?

You have a database that contains the following tables:

You need to write a query that returns a list of all customers who have not placed orders.
Which Transact-SQL statement should you run?

You have a database that contains the following tables:

You need to write a query that returns a list of all customers who have not placed orders.
Which Transact-SQL statement should you run?

A.
SELECT c.custid FROM Sales.Customers c INNER JOIN Sales.Order o ON c.custid = o.custid

B.
SELECT custid FROM Sales.Customers INTERSECT SELECT custid FROM Sales.Orders

C.
SELECT c.custid FROM Sales.Customers c LEFT OUTER Sales.Order o ON c.custid = o.custid

D.
SELECT c.custid FROM Sales.Customers c LEFT OUTER JOIN Sales.Order oON c.custid = o.custid
WHERE orderid IS NULL

Explanation:
Inner joins return rows only when there is at least one row from both tables that matches the join condition.
Inner joins eliminate the rows that do not match with a row from the other table. Outer joins, however, return all
rows from at least one of the tables or views mentioned in the FROM clause, as long as those rows meet any
WHERE or HAVING search conditions. All rows are retrieved from the left table referenced with a left outer join,
and all rows from the right table referenced in a right outer join. All rows from both tables are returned in a full
outer join.
https://technet.microsoft.com/en-us/library/ms187518(v=sql.105).aspx



Leave a Reply 2

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


davgmane

davgmane

D is correct