Skip to content
Advertisement

mysql – common table expressions: simulated full join

i have multiple (more than 20) cte’s which i need to join together to output the rows side by side.

this works for the first two cte’s…

this gives an error…

so how can i add the other cte’s to the game?

Advertisement

Answer

That union approximation of full joins is still around? It is an awful approach — not quite equivalent in functionality and much more expensive than necessary.

For your problem, use union all and aggregation. One method is:

Adding more CTEs is as simple as adding more UNION ALL clauses in the subquery and then added more MAX(CASE) expressions in the outer query.

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