exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 116 discussion

Actual exam question from Microsoft's 70-761
Question #: 116
Topic #: 1
[All 70-761 Questions]

Note: This question is part of a series of questions that use the same or similar answer choices. An answer choice may be correct for more than one question in the series. Each question is independent of the other questions in this series. Information and details provided in a question apply only to that question.
You have a database that contains tables named Customer_CRMSystem and Customer_HRSystem. Both tables use the following structure:

The following records exist in the tables:

Customer_CRMSystem -


Customer_HRSystem -

Records that contain null values for CustomerCode can be uniquely identified by CustomerName.
You need to display distinct customers that appear in both tables.
Which Transact-SQL statement should you run?

A.

B.

C.

D.

E.

F.

G.

H.

Show Suggested Answer Hide Answer
Suggested Answer: H
To retain the nonmatching information by including nonmatching rows in the results of a join, use a full outer join. SQL Server provides the full outer join operator,
FULL OUTER JOIN, which includes all rows from both tables, regardless of whether or not the other table has a matching value.
Incorrect Answers:
A: 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.
B: INTERSECT returns distinct rows that are output by both the left and right input queries operator.
D: EXCEPT returns distinct rows from the left input query that aren't output by the right input query.
E: UNION specifies that multiple result sets are to be combined and returned as a single result set, but this will not work here as the CustomerID column values do not match.
F: UNION ALL incorporates all rows into the results. This includes duplicates. If not specified, duplicate rows are removed.
G: A cross join would produce the Cartesian product of the two tables.
References:
https://technet.microsoft.com/en-us/library/ms187518(v=sql.105).aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Dieter
Highly Voted 5 years, 10 months ago
In my opinion the correct answer is to use INTERSECT since we only want to see the distinct customers which are in both tables. or do I misunderstand?
upvoted 25 times
AshleyLiang
5 years, 10 months ago
Agree. The JOINs don't match NULLs but set operators do.
upvoted 5 times
...
imran
5 years, 8 months ago
INTERSECT WILL ONLY GIVE YOU 3 ROW WHICH ARE COMMON IN BOTH TABLES. HOWEVER YOU SHOULD USE UNION TO BRING ALL THE DISTINCT VALUES FROM BOTH TABLE USING UNION WILL GIV YOU 6 ROWS WHICH IS CORREECT ANSWER. THANKS
upvoted 4 times
SlazericeQ
5 years, 5 months ago
I think it depends how u understood the question, which is according my opinion a little bit confusing. I believe they ask for distinct customers across both tables not for each table.
upvoted 4 times
...
OJ97
4 years, 5 months ago
The question asked for names that appear in both tables... (Intersect)
upvoted 1 times
...
...
AnsB
5 years, 4 months ago
the answer is correct. Intersect will miss CUS9 YOSSI
upvoted 1 times
...
chaoxes
4 years, 11 months ago
No, INTERSECT will return only 3 rows that appear in both tables: NULL Jane CUS1 Roya CUS9 Yossi Correct answer is E using UNION, it will return 6 distinct rows. Answer H with full outer join return 7 rows, as it doubles NULL JANE twice, therefore its not distinct
upvoted 3 times
...
...
bzub
Highly Voted 5 years, 3 months ago
INTERSECT is correct, try it yourself: CREATE TABLE Customer_CRMSystem ( CustomerID INT NOT NULL PRIMARY KEY NONCLUSTERED, CustomerCode char(4) NULL, CustomerName varchar(50) NOT Null ) CREATE TABLE Customer_HRSystem ( CustomerID INT NOT NULL PRIMARY KEY NONCLUSTERED, CustomerCode char(4) NULL, CustomerName varchar(50) NOT Null ) SELECT c.CustomerCode, c.CustomerName, h.CustomerCode, h.Customername FROM Customer_CRMSystem c LEFT JOIN Customer_HRSystem h ON c.CustomerCode = h.CustomerCode AND c.CustomerName = h.CustomerName SELECT CustomerCode, CustomerName FROM Customer_CRMSystem INTERSECT SELECT CustomerCode, CustomerName FROM Customer_HRSystem
upvoted 6 times
...
Billybob0604
Most Recent 4 years, 5 months ago
I'd say intersect has been invented for this to give the distinct values across multiple tables.
upvoted 1 times
...
Vermonster
4 years, 5 months ago
INTERSECT is the only option that returns all 4 matching records
upvoted 1 times
...
kimalto452
4 years, 6 months ago
you need customer that appears IN BOTH TABLE if in one table customer not appear YOU DONT NEED HIM. Correct answer is intercept
upvoted 1 times
...
Andy7622
4 years, 6 months ago
The correct is one with INTERSECT .only this gives distinct entities that are presented in both tables.
upvoted 1 times
...
SimSql
4 years, 6 months ago
Hello, The question is asking for DISTINCT customers that appear in both tables, and records that contain NULL values for customerCode are uniquely identified by CustomerName. Just looking at the tables Jane, Roya and Yossi are the three distinct customers that appear in both. INTERSECT does give distinct cutomers.
upvoted 1 times
...
SimSql
4 years, 6 months ago
Hello, The question is asking for DISTINCT customers that appear in both tables, and records that contain NULL values for customer are uniquely identified by CustomerName. Just looking at the tables Jane, Roya and Yossi are the three distinct customers that appear in both. INTERSECT does give distinct customers.
upvoted 1 times
...
BabyBee
4 years, 7 months ago
I understood using UNION. DROP TABLE IF EXISTS Customer_CRMSystem; CREATE TABLE Customer_CRMSystem (CustomerID tinyint, CustomerCode char(4), CustomerName varchar(50)); INSERT INTO Customer_CRMSystem VALUES ( 1, 'CUS1', 'Roya') ,(2, 'CUS9', 'Yossi') ,(3, 'CUS4', 'Jack') ,(4, NULL, 'Jane') ,(5, NULL, 'Francisco'); DROP TABLE IF EXISTS Customer_HRSystem; CREATE TABLE Customer_HRSystem (CustomerID tinyint, CustomerCode char(4), CustomerName varchar(50)); INSERT INTO Customer_HRSystem VALUES ( 1, 'CUS1', 'Roya') ,(2, 'CUS2', 'Jose') ,(3, 'CUS9', 'Yossi') ,(4, NULL, 'Jane'); SELECT CustomerCode, CustomerName FROM Customer_CRMSystem UNION SELECT CustomerCode, CustomerName FROM Customer_HRSystem;
upvoted 1 times
...
Aghie
4 years, 10 months ago
"You need to display distinct customers that appear in both tables." INTERSECT is the right answer for this as the 3 customers (Jane, Roya, Yossie) appeared in both tables. UNION will return the all distinct customers for each table combined. (All 6 customers)
upvoted 4 times
...
rustyG
5 years ago
the question is too vague, declare @CRMSystem table ( CustomerID INT, CustomerCode char(4) NULL, CustomerName varchar(50) NOT Null ) declare @HRSystem table ( CustomerID INT NOT NULL PRIMARY KEY NONCLUSTERED, CustomerCode char(4) NULL, CustomerName varchar(50) NOT Null ) INSERT INTO @CRMSystem(CustomerID, CustomerCode, CustomerName ) VALUES (1, 'cus1', 'Roya') , (2, 'cus9', 'Yossi') , (3, 'cus4', 'Jack') , (4, null, 'Jane') , (5, null, 'Francisco') INSERT INTO @HRSystem(CustomerID, CustomerCode, CustomerName ) VALUES (1, 'cus1', 'Roya') , (2, 'cus2', 'Jose') , (3, 'cus9', 'Yossi') , (4, null, 'Jane') SELECT c.CustomerCode, c.CustomerName, h.CustomerCode, h.Customername FROM @CRMSystem c full outer JOIN @HRSystem h ON c.CustomerCode = h.CustomerCode AND c.CustomerName = h.CustomerName SELECT CustomerCode, CustomerName FROM @CRMSystem INTERSECT SELECT CustomerCode, CustomerName FROM @HRSystem
upvoted 2 times
...
Anette
5 years, 1 month ago
Correct answer is INTERSECT (B). Tested
upvoted 2 times
...
gtc108
5 years, 4 months ago
INTERSECT will return values that's distinct from both queries however FULL OUTER JOIN will return customerID=5 which is not in the HR system with NULL so the answer is B.
upvoted 2 times
...
fabzo
5 years, 7 months ago
INTERESCT is the correct answer not sure why this site has mostly incorrect answers. I've tested this and intersect returns distinct customers that appear in both tables :/
upvoted 5 times
flashed
5 years, 4 months ago
No, intersect gives: NULL Jane CUS1 Roya CUS9 Yossi UNION gives: NULL Francisco NULL Jane CUS1 Roya CUS2 Jose CUS4 Jack CUS9 Yossi For me correct anwser is UNION
upvoted 12 times
chaoxes
4 years, 11 months ago
I tested it and confirm, correct answer is E using UNION
upvoted 3 times
...
...
...
mlourinho
5 years, 7 months ago
"distinct customers that appear in both tables" can have 2 meanings: 1. distinct customers that appear in both tables 2. distinct customers for each table In this case, I think they asked "distinct customers for each table"..
upvoted 2 times
mlourinho
5 years, 7 months ago
I was wrong: the question demands "distinct customers", and with the FULL OUTER JOIN you don't have that. So the right answer is INTERSECT. Also INTERSECT also consider the Null Values, and in this case the FULL OUTER JOIN will not consider those values to connect records (and it should).
upvoted 3 times
...
...
dragan
5 years, 9 months ago
I think B
upvoted 2 times
...
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.

SaveCancel
Loading ...