Skip to content
Advertisement

SQL Join – If it doesn’t find any, try another parameters

Let’s suppose we have the following query:

If that LEFT JOIN doesn’t find nothing, I need to change the ON parameters to something like:

That second LEFT JOIN only needs to run if the first one doesn’t return nothing. How can I achieve that behaviour?


I have already tried with an OR statement, but doesn’t work because the first LEFT JOIN always need to be checked first, and not at the same time that the second.

Advertisement

Answer

Perhaps the simplest method is union all:

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