Last active
October 2, 2018 21:55
-
-
Save gdoddsy/8e061026066c26c831ed438430f861f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Use a Where Clause | |
SELECT Posts.Title | |
,acceptedAnswer.CreationDate | |
,Users.DisplayName | |
FROM dbo.Posts | |
LEFT JOIN dbo.Posts AS acceptedAnswer | |
ON acceptedAnswer.Id = Posts.AcceptedAnswerId | |
LEFT JOIN dbo.Users | |
ON acceptedAnswer.LastEditorUserId = Users.Id | |
WHERE Posts.PostTypeId = 1 | |
AND | |
( ( acceptedAnswer.Id IS NULL AND Users.Id IS NULL) | |
OR ( acceptedAnswer.Id IS NOT NULL AND Users .Id IS NOT NULL) | |
) | |
--Use a nested join | |
SELECT Posts.Title | |
,acceptedAnswer.CreationDate | |
,Users.DisplayName | |
FROM dbo.Posts | |
LEFT JOIN dbo.Posts AS acceptedAnswer | |
INNER JOIN dbo.Users | |
ON acceptedAnswer.LastEditorUserId = Users.Id | |
ON acceptedAnswer.Id = Posts.AcceptedAnswerId | |
WHERE Posts.PostTypeId = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment