I have an SQL query
SELECT * FROM A FULL OUTER JOIN B ON A.z = B.z WHERE A.z = 1 OR B.z = 1
where A.z and B.z are primary keys.
The purpose is to do a full outer join on two tables whilst their primary keys match a given value – so that only one row is returned.
But I got confused on how to extend it to 3 or more tables. The restriction that their primary keys match a given index so that only one row is return in total remains. How do you do it?
First, note that in the provided query, the
FULL OUTER JOINthat you request could be rewritten as:which makes (IMO) more clear what the data sources are and what the join condition is. For a moment, with your
WHEREcondition, I had the feeling that you wanted actually an INNER JOIN.With this you can extend more easily probably: