0
SELECT MP.* FROM SurveyFrontend..WebResult WR JOIN MeetingHistory MH ON MH.WebResultID=WR.WebResultID JOIN Meeting M ON MH.MeetingID=M.MeetingID JOIN MeetingPlanner MP ON MP.MeetingPlannerID=M.MeetingPlannerID WHERE PrimaryEntityID=2424 AND WR.TimeResultTaken>='1/1/2016' AND CardSet=2 

I've looked it up but I can't find any examples on how to do a full outer join with multiple joins. I want to pull the exact opposite of the above query.

How would I go about doing this?

Here is exactly what I'm looking for:

SQL FULL OUTER JOIN

Updated code:

SELECT MP.* FROM SurveyFrontend..WebResult WR FULL OUTER JOIN MeetingHistory MH ON MH.WebResultID=WR.WebResultID FULL OUTER JOIN Meeting M ON MH.MeetingID=M.MeetingID FULL OUTER JOIN MeetingPlanner MP ON MP.MeetingPlannerID=M.MeetingPlannerID WHERE PrimaryEntityID=2424 AND WR.TimeResultTaken>='1/1/2016' AND CardSet=2 AND (MH.WebResultID IS NULL OR MH.MeetingID IS NULL OR MP.MeetingPlannerID IS NULL OR WR.WebResultID IS NULL OR M.MeetingID IS NULL OR M.MeetingPlannerID IS NULL) 
5
  • 2
    Replace all instances of JOIN here (which is implicitly an INNER JOIN) with FULL OUTER JOIN, WHERE anyA key(s) are NULL or any B keys are NULL. The syntax is shown in the image you cropped: codeproject.com/KB/database/Visual_SQL_Joins/… Commented May 28, 2016 at 0:59
  • I know that part but I don't know what to put in the WHERE clause. Thank you though! Commented May 28, 2016 at 1:01
  • Oh nvm, you edited your comment. Let me try that out. Commented May 28, 2016 at 1:02
  • I'm not getting any returns with the updated statement* Commented May 28, 2016 at 1:10
  • I also switched the and's to or's Commented May 28, 2016 at 1:14

1 Answer 1

1

full outer join returns all rows which match on condition and all rows from left table which don't match condition and all rows from right table which don't match condition. Any where restrictions reduce full outer join to left, right, or inner join. Some examples:

create table #a(id int, name varchar(10)) insert #a values (1,'test1'),(2,'test2'),(3,'test3') create table #b(id int, name varchar(10)) insert #b values (1,'test1'),(4,'test4'),(5,'test5') select a.id aid,a.name aname, b.id bid,b.name bname from #a a full outer join #b b on a.id=b.id --same as left join select a.id aid,a.name aname, b.id bid,b.name bname from #a a full outer join #b b on a.id=b.id where a.id=2 --same as right join select a.id aid,a.name aname, b.id bid,b.name bname from #a a full outer join #b b on a.id=b.id where b.id=4 --same as inner join select a.id aid,a.name aname, b.id bid,b.name bname from #a a full outer join #b b on a.id=b.id where a.id=1 and b.id=1 --same as inner join better example select a.id aid,a.name aname, b.id bid,b.name bname from #a a full outer join #b b on a.id=b.id where a.id = b.id 
Sign up to request clarification or add additional context in comments.

1 Comment

Tests of is null in the where clause don't always reduce full outer to a left, right, or inner join. Specifically LeftPK is null or RightPK is null gives rows from both side that don't have matches.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.