I want to do a PHP MySQL query performance efficient. So If I have a lot of LEFT JOIN’s, I do not need them all the time, only if other conditions are met by another LEFT JOIN.
So is it even possible to run LEFT join in a query only if another left join variable meets the need.
LEFT JOIN page ON main.id=page.id and main.type=0 LEFT JOIN permission ON permission.pageid=page.id and permission.userid=? and page.state='MembersOnly'
So I would like to run The Second LEFT JOIN db check ONLY if the first JOIN PageState equals to “MembersOnly”.
This code checks both JOINS always/all the time, and maybe more efficient is to add separate queries inside a loop if these rare conditions are met, or else, in the end there would be like 10 of extra JOINS.
I don’t think it is possible, but I am not an expert so I decided to ask.
If anyone knows more please let me know,