I am having trouble working out how to user Inner Join correctly and targeting other tables for multiple conditions within one MySQL query.
Basically, I am creating a small follower feed for my Website, which outputs new posts from any user that you are following.
Posts Table:
id | user_id | message | timestamp
Follow Table:
id | follower_id | following_id
My Query up to now:
SELECT posts.*
FROM posts
INNER JOIN follows
ON posts.user_id = follows.following_id
WHERE follows.follower_id = 1
ORDER BY id DESC limit 10
How could I add a condition in there to: 1.) Greater than or Less than an ID (posts.id) 2.) Specify that it can also be posted by the User ID of 1 (My own posts)
Of course, the 1 will be replaced by a variable so it is dynamic for the current user session.
Any suggestions here, getting really confused by it.
ON ...) - you can just put anORthere. The same goes for 1). You just have to add a parameter to the query from thePHPlevel.