I have a MySQL query that is baffling me. I am trying to grab specific pieces of information from two different tables (blurbs and users), while restricting it to only people who are following.
I have the following query:
SELECT DISTINCT blurbs.text, blurbs.timestamp, users.name,
users.username, users.profilepic, users.id
FROM blurbs,users
LEFT OUTER JOIN follows
ON blurbs.uid = follows.following AND follows.follower = ?
WHERE (blurbs.uid = $user_id OR follows.following IS NOT NULL)
AND (LOWER(blurbs.text) LIKE '%$query%' OR LOWER(users.name) LIKE '%$query%')
AND blurbs.is_private=0 AND blurbs.uid=users.id
LIMIT 0,30
It’s not working properly, but I am getting overly confused because of the joins.
What should I do to remedy this?
Try using all the join condition through where clause only e.g.
Trying to rephrase your query as below:
Having done this, I hope you can better control/manage the desired filter conditions.