I need to return all items from ‘t’ (thread) that include ‘menu_item_id’ = 1.
In addition, I need to filter all the above results based on f.tag.
SELECT t.*, u.username AS owner, uu.username AS replyname, a.location
FROM thread t
INNER JOIN filter_thread as ft ON t.thread_id = ft.thread_id
INNER JOIN filter as f ON f.filter_id = ft.filter_id
INNER JOIN users u ON t.owner_id = u.id
INNER JOIN users uu ON t.last_post_id = uu.id
INNER JOIN user_profiles AS up ON u.id = up.user_id
INNER JOIN avatars AS a ON up.avatar_id = a.id
WHERE t.menu_item_id='1'
AND f.tag LIKE '%hello%'
OR f.tag LIKE '%world%'
problem area: AND f.tag LIKE '%hello%'
OR f.tag LIKE '%world%'
The important thing to realize is that ‘hello’ and ‘world’ might not always be in the query. In addition, there might be 3 more searches tacked onto it, however, the menu_item_id will always be searched for.
I don’t want all the results to require each of the f.tags, i just want to the results to contain any of them (OR).
Any help would be appreciated.
Use parenthesis to specify the precedence of the
ANDandOR.vs.
For example:
This will return only rows that have menu_item_id = ‘1’ AND which have tag containing either ‘hello’ or ‘world’.