I built a large script with several inner joins working as “conditions” (instead of using WHERE clauses). As a sample:
SELECT T1.*
FROM Table1 T1
INNER JOIN Table2 T2
ON T1.id = T2.id
INNER JOIN Table3 T3
ON T2.id = T3.id
INNER JOIN Table4 T4
ON T1.id = T4.id
etc…
Under certain conditions I need to skip one or several inner joins.
Till now, I had to duplicate the script commenting out the lines with the joins I don’t need.
Would it be any way to work with variables or IF clauses to skip a join, or at least a “select all” way?
Assuming php:
But I’m sure you should rather build the query dynamically:
etc. with all your joins.