thanks for taking the time to read this.
Essentially I have 3 tables. Posts, Follows, Artists. What I am trying to do is pull all the ‘Posts’ from ‘Artists’ that the user ‘Follows’. I am passing the user_id in, and trying to pull data from ‘Posts’ and ‘Artists’
Posts /* the posts table */
id
body
artist_id
timecode
Follows /* the follows table */
id
artist_id
user_id
Artists /* the artists table */
id
name
So, my basic query starts out like this:
SELECT Posts.id,Posts.body,Posts.timecode,Artists.id AS artist_id,Artists.name
FROM Posts,Artists
LEFT JOIN Artists
ON Posts.artist_id = Artists.id
Now this is where I start to get confused. I am guessing that I need another JOIN statement on the “Follows” table so that I limit the returned results to rows that have a “follows” entry with both the user_id and artist_id.
ie:
RIGHT JOIN Follows
ON Posts.artist_id = Follows.artist_id
WHERE Follows.user_id = :userid
My problem is that I’m not really even sure how to write this properly, although I feel like i’m on the right track here… sorta
ANY help would be much appreciated!!! Thanks.
EDIT Please note I am pulling data from both the Posts and Artists tables, not just the Posts table. Not sure if this makes a big difference.
Haven’t checked the syntax I hope it is ok.