0
I have two tables (posts and posts_promoted). Both relate and the search "normal" works smoothly. However, I need to do a search to return all posts and, if the post belongs to posts_promoted, bring me only posts_promoted with status = "N".
I tried something like
SELECT * FROM posts AS POST [...] WHERE [..] AND IF((SELECT COUNT(*) FROM posts_promovidos WHERE posts_promovidos.post_id = post.id) > 0,posts_promovidos.ativo = "N","")
However it did not work as wanted because it is only bringing the promoted posts and ignoring the posts "not promoted" (that do not appear in the posts_promoted table).
What would be the most correct way to do this search?
EDIT - SOLUTION
I decided as follows (sharing to help anyone who has something similar):
SELECT * FROM posts AS POST [...] WHERE [..] AND posts.id NOT IN(select post_id from posts_promovidos) OR posts_promovidos.ativo = "N"
I already have JOIN properly configured and working. I only have this question of, in some cases, check if the post is on posts_promoted and, if it is, that it is not active (active = "N"). JOIN is unconditional, ie,.
– Danilo Miguel