Provide brief explanation of following SQL code

This is one of the questions I have on my interview exam. It is a take home exam and I have not learned SQL but the employers want to know my know my skills to find answers using any means possible.

Question: Review the following SQL code and give a brief explanation


SELECT 'AD', B.AccountID,'Change'
FROM
(SELECT DISTINCT A.sAMAccountName As AccountID from
(select AG.sAMAccountName from AD_Groups_Feed AGF FULL OUTER

JOIN AD_Groups AG ON AGF.GroupName = AG.GroupName AND AGF.sAMAccountName = AG.sAMAccountName WHERE AGF.GroupName Is NULL AND AG.sAMAccountName NOT IN (select AccountID from Exceptions where TargetID='AD')
UNION
select AGF.sAMAccountName from AD_Groups_Feed AGF FULL OUTER JOIN AD_Groups AG ON AGF.GroupName = AG.GroupName AND AGF.sAMAccountName = AG.sAMAccountName WHERE AG.GroupName Is NULL
AND AGF.sAMAccountName NOT IN (select AccountID from Exceptions where TargetID='AD')) A
WHERE A.sAMAccountName NOT IN (select AccountID from Exceptions where TargetID='AD'))B

Questions by krypt83

Showing Answers 1 - 3 of 3 Answers

ajith007

  • Dec 6th, 2007
 

Use of distinct, not in keywords make this code altogether complicated. But what I discern from this code 'catch' lies in FULL OUTER JOIN since it retreives all the data including your null values.
The union here returns the cross product of query mentioned that includes your null values.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions