I have 3 table on my mysql db (user, follower, post), I wrote an sql, that get all posts from the people a user followed.
sql
SELECT post.* FROM post JOIN
follower ON post.owner_user_id = follower.user_id AND
follower.follower_id = "3"
result
id | owner_user_id | content
2 | 1 | why are all my senior developers jerks?
3 | 1 | PHP7 in your face node.js
user table
id | username | password
1 | user1 | 12345678
2 | user2 | 12345678
3 | user3 | 12345678
follower table
user_id | follower_id
3 | 1
3 | 2
1 | 3
post table
id | owner_user_id | content
1 | 2 | reading a 1k+ page on mysql, do i need to?
2 | 1 | why are all my senior developers jerks?
3 | 1 | PHP7!, in your face node.js
3 | 3 | I posted
so now am trying to select post of people the user is following and the posts of the user
I tried this sql
sql
SELECT post.* FROM post JOIN
follower ON post.owner_user_id = follower.user_id AND
follower.follower_id = "3" JOIN
user ON post.owner_user_id = user.id= "3"
result
null
Please is what am trying to achieve with the sql possible, if(possible) {"what_am_i_doing_wrong"}();
edits
user_id 3 has a post, still running the above sql returns null, was hoping if the user had no post, only post of the people the user is following is returned
select post.* from
(select user_id from follower where follower_id = 3 union select 3) blah
join post on blah.user_id = post.owner_user_id;
Try this:
SELECT Distinct post.* FROM post JOIN
follower ON post.owner_user_id = follower.user_id JOIN
user ON follower.user_id = user.id WHERE user.id = 3
You shuldn't use conditions in JOIN statement, use WHERE instead.