[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Full Outer Join (More Than Two Tables)

Posted on 2006-03-21
2
Medium Priority
?
3,786 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:Mick_Rice
2 Comments
 
LVL 19

Expert Comment

by:NickUpson
ID: 16249566
"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
0
 
LVL 42

Accepted Solution

by:
dqmq earned 2000 total points
ID: 16252571
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:

tblSong
SongID
----  
s1      
s2
s3

tblAlbum
AlbumID  
----
a1  
a2
a3  

tblRelease
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

returns:
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
                 

   
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question