Skip to content
Advertisement

Is it possible to write a SQL for all matchs in a triple join with no unions?

I’d like to perform a SQL join for the grey painted region of the following Venn diagram, but using no UNIONs:

Venn diagram triple join

Please, is it possible?

For the sake of simplicity, think all tables with only two columns: id and value, id is the same for all of them.

Here’s a sample data:

Advertisement

Answer

You can full join twice and add conditional logic in the where clause:

Not all databases support that syntax. A more widely supported approach is indeed to use union all and aggregation:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement