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 o ON c.custid = o.custid WHERE orderid IS NULL
E.
SELECT custid FROM Sales.Customers UNION ALL SELECT custid FROM Sales.Orders
F.
SELECT custid FROM Sales.Customers UNION SELECT custid FROM Sales.Orders
G.
SELECT c.custid FROM Sales.Customers c RIGHT OUTER JOIN Sales.Orders o ON c.custid = o.custid
Suggested Answer:D🗳️
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. References: https://technet.microsoft.com/en-us/library/ms187518(v=sql.105).aspx
D is correct, although I wouldn't write it that way, I would write:
select CustID from Customers as C where not exists ( select 1 from Orders as O where O.CustID = C.CustID)
My bad, G returns all orders and customers that have orders. Sry.
upvoted 1 times
...
...
This section is not available anymore. Please use the main Exam Page.70-761 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
stm22
Highly Voted 4 years, 11 months agookus
4 years, 11 months agokiri2020
Most Recent 4 years, 8 months agoOrleD
4 years, 10 months agoOrleD
4 years, 10 months ago