I want to perform a conditional right join in this SQL
SELECT *
FROM post
IF 1 = 1 THEN RIGHT JOIN faves ON faves.post_id_fk = post_id; // <== error
END IF;
WHERE post_author_id
LIKE 1
ORDER BY post_timestamp DESC
LIMIT 0, 10
Is there a better/right way of doing this?
From where does your condition originate?
If it comes from outside of SQL, why not determine whether or not to put the join into your query at that level:
Otherwise, if it must be tested within SQL, I’d separate the different statements apart: