exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 82 discussion

Actual exam question from Microsoft's 70-761
Question #: 82
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 to that question.
You have a database for a banking system. The database has two tables named tblDepositAcct and tblLoanAcct that store deposit and loan accounts, respectively. Both tables contain the following columns:

You need to run a query to find the total number of customers who have both deposit and loan accounts.
Which Transact-SQL statement should you run?

A.

B.

C.

D.

E.

F.

G.

H.

Show Suggested Answer Hide Answer
Suggested Answer: A
The SQL INTERSECT operator is used to return the results of 2 or more SELECT statements. However, it only returns the rows selected by all queries or data sets. If a record exists in one query and not in the other, it will be omitted from the INTERSECT results.
References:
https://www.techonthenet.com/sql/intersect.php

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
vramky
4 years, 4 months ago
It is not INTERSECT because the "INTERSECT operator is used to return the records that are in common between two SELECT statements or data sets. If a record exists in one query and not in the other, it will be omitted from the INTERSECT results. It is the intersection of the two SELECT statements." So, if a customer has a deposit account, but not a loan account (null), the record will be omitted from the result set. The question asks for "all ("?) customers who have both deposit and loan accounts". It is how we interpret this phrase that will decide the correct answer ?
upvoted 1 times
...
vramky
4 years, 4 months ago
UNION ALL. Please read question and description. "all customers" who have both loan and deposit accounts.
upvoted 1 times
...
kimalto452
4 years, 4 months ago
A is ok , custNo and AccNo( PK ) its the same... read description of column...
upvoted 1 times
zezima
4 years, 4 months ago
No a PK identifies unique rows, not unique customers...
upvoted 1 times
...
...
KosteK
4 years, 5 months ago
UNION ALL SELECT 'F', count(*),'Total number of customers who have only deposit accounts' FROM ( SELECT CustNo FROM #tblDepositAcct D EXCEPT SELECT CustNo FROM #tblLoanAcct L ) R UNION ALL SELECT 'G', count(DISTINCT COALESCE(d.CustNo, l.CustNo)),'#80: Total number of customers who have either deposit accounts or loan accounts, but not both types of accounts' FROM #tblDepositAcct D FULL JOIN #tblLoanAcct L ON d.CustNo=l.CustNo WHERE d.CustNo IS NULL OR l.CustNo IS NULL UNION ALL SELECT 'H', count(*),'' FROM #tblDepositAcct D FULL JOIN #tblLoanAcct L ON d.CustNo=l.CustNo
upvoted 1 times
...
KosteK
4 years, 5 months ago
SELECT 'A' 'Ans', count(*) 'Count', 'The same Accounts in two tables' 'Desc' FROM ( SELECT AcctNo FROM #tblDepositAcct D INTERSECT SELECT AcctNo FROM #tblLoanAcct L ) R UNION ALL SELECT 'B', count(*),'Distict customers' FROM ( SELECT CustNo FROM #tblDepositAcct D UNION SELECT CustNo FROM #tblLoanAcct L ) R UNION ALL SELECT 'C', count(*),'Count of all Acc' FROM ( SELECT CustNo FROM #tblDepositAcct D UNION ALL SELECT CustNo FROM #tblLoanAcct L ) R UNION ALL SELECT 'D', COUNT (DISTINCT D.CustNo),'#82: Total number of customers who have both deposit and loan accounts' FROM #tblDepositAcct D, #tblLoanAcct L WHERE D.CustNo = L.CustNo UNION ALL SELECT 'E', COUNT (DISTINCT L.CustNo),'#81: Total number of customers who have only loan accounts' FROM #tblDepositAcct D RIGHT JOIN #tblLoanAcct L ON D.CustNo=L.CustNo WHERE D.CustNo IS NULL
upvoted 1 times
...
KosteK
4 years, 5 months ago
DROP TABLE IF EXISTS #tblDepositAcct CREATE TABLE #tblDepositAcct ( CustNo int, AcctNo int PRIMARY KEY, ProdCode varchar(3) ); DROP TABLE IF EXISTS #tblLoanAcct CREATE TABLE #tblLoanAcct ( CustNo int, AcctNo int PRIMARY KEY, ProdCode varchar(3) ); INSERT INTO #tblDepositAcct VALUES (1,100,'a') ,(1,200, 'b') ,(2, 300, 'c') ,(3, 400, 'd') ,(3, 500, 'd') ,(3, 600, 'd'); INSERT INTO #tblLoanAcct VALUES (1,500,'g') ,(2,600, 'h') ,(4,700, 'c') ,(4,800, 'i') ,(5,900, 'j') ,(6,1000, 'j');
upvoted 1 times
...
BabyBee
4 years, 5 months ago
DROP TABLE IF EXISTS #tblDepositAcct CREATE TABLE #tblDepositAcct ( CustNo int, AcctNo int PRIMARY KEY, ProdCode varchar(3) ); DROP TABLE IF EXISTS #tblLoanAcct CREATE TABLE #tblLoanAcct ( CustNo int, AcctNo int PRIMARY KEY, ProdCode varchar(3) ); INSERT INTO #tblDepositAcct VALUES (1,100,'abc') ,(2,200, 'def') ,(3, 300, 'ghi') ,(1, 400, 'jkl'); INSERT INTO #tblLoanAcct VALUES (1,500,'mno') ,(2,600, 'pqr'); SELECT * FROM #tblDepositAcct; SELECT * FROM #tblLoanAcct; --D SELECT COUNT (DISTINCT D.CustNo) FROM #tblDepositAcct D, #tblLoanAcct L WHERE D.CustNo = L.CustNo; --RETURNS 2 (Correct is D)
upvoted 2 times
...
HA2020
4 years, 5 months ago
Sorry, only D is correct.
upvoted 1 times
...
HA2020
4 years, 5 months ago
Both D & G are correct
upvoted 1 times
...
Aghie
4 years, 8 months ago
Tested. D is correct. the syntax in A is correct except the join. its supposed to be CustNo no AcctNo.
upvoted 2 times
Aghie
4 years, 8 months ago
*not AcctNo
upvoted 1 times
...
...
Backy
4 years, 10 months ago
A is incorrect, both tables use different values of AcctNo for the same customer, so INTERSECT will be empty D is correct
upvoted 3 times
...
Anette
4 years, 11 months ago
Both A and D seems to be right. A - counts the Account Number once in one table and D counts the customer number
upvoted 1 times
Anette
4 years, 11 months ago
But D is the right one :) TESTED
upvoted 7 times
tz_123
4 years, 10 months ago
Correct, for the same reason mlourinho gave above: since "A customer may have multiple accounts for the same product type" and the question is about the number of Customers, then A is wrong.
upvoted 3 times
...
...
...
raf77
5 years, 8 months ago
A is wrong - question concern customers, not accounts. D seems ok
upvoted 4 times
Bartek
5 years, 7 months ago
nope, A is fine.
upvoted 8 times
raf77
5 years, 7 months ago
Indeed A is fine. My mistake. Thank you.
upvoted 2 times
Tazul
5 years, 7 months ago
wrong because A used AcctNo, not CustNo D is correct
upvoted 20 times
jpdvm
5 years, 2 months ago
The FROM syntax in D is not correct, so all answers are wrong
upvoted 1 times
lh2607
4 years, 4 months ago
It's not wrong syntax. An implicit join is being used.
upvoted 1 times
...
...
...
...
Ashfaq46
4 years, 6 months ago
A and D both are wrong, the question is we need to count distinct customers from both the account. A and D will count only from deposit account. Here we need to use union and the correct Answer should be option B which will give distinct count from both tables.
upvoted 1 times
...
...
mlourinho
5 years, 5 months ago
Since "A customer may have multiple accounts for the same product type" and the question is about the number of Customers, then A is wrong.
upvoted 4 times
Alsari
4 years, 4 months ago
INTERSECT IS DISTINCT
upvoted 1 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago