Full Outer Join (More Than Two Tables)

I'm not even sure myself if this makes sense but can you join more than two tables with the new FULL outer join syntax.

For example if I have three tables can I join all three hoping to return all rows on all three tables only matching rows where the join condition is satisfied.

If this is possible, or even logical, give a code example.
Who is Participating?
Haven't tried it, but I don't see any reason why full outer join across three tables wouldn't work. In reality, it's just two successive full outer joins:  Table1 full outer join table2 produces a result set and then full outer join that result set to table3.  

The result of a full outer join is the same as inner joining two tables then adding the rows in each table that do not have a matching row in the other table.  Columns from the missing table are represented by nulls.  

For example:



AlbumID  SongID
---------   --------
a1           s1
a2           s1
a2           s2  

Select * from tblSong as s
full outer join tblRelease as r on s.songID = r.SongID
full outer join tblAlbum   as a on a.albumID = r.AlbumID

s.songid       r.songid      r.albumid       a.albumID
---------       ---------       ----------        -----------
s1               s1               a1                 a1
s1               s1               a2                 a2
s2               s2               a2                 a2
s3               null             null               null
null             null             null                a3

Nick UpsonPrincipal Operations EngineerCommented:
"only matching rows where the join condition is satisfied." - this requires only an inner join between the tables

taking a 2 table example, customers and invoices, inner join them and get a list of all invoices that have a valid customer (or all customers that have a valid invoice - it's the same) left/right outer join them and get either all customers with their invoices, if they have any, or all invoices with a valid customer, full outer join will list all customers and all invoices, showing where they link
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.