I have a query that I am getting post from a database. I have a 3 table join to get posts, profile picture, and user names. The current query is below.
SELECT Posts.*, Profiles.ProfilePhoto, Users.Name, Users.Username
FROM ((Posts
INNER JOIN Profiles ON Posts.UserID = Profiles.UserID)
INNER JOIN Users ON Posts.UserID = Users.ID)
WHERE Posts.UserID = ?
ORDER BY Posts.CreateDate DESC
Right now I am getting the data from the user's posts (where posts.userID = ?). But i wanted to extend the query to also get the posts from users that the he/she follows.
That would need me adding something like another inner join like
INNER JOIN Follow ON Posts.UserID = Follow.Followed (WHERE Follow.Follower = ?) // ? being $userID;
But that isn't going to work because you can't throw that WHERE statement to the end of the inner join. So I was wondering what the most efficient way to add that into the current query would be?
Profiles.ProfilePhoto, Users.Name, Users.Usernamecolumns? The target UserId's profile/user/username or the users who posted the posts?