I am designing a site like pinterest ( for study ) and I want to know what query I have to do at the homepage to show the user's stream.
I have created these 6 tables:
users
boards
pictures
boards_pictures ( many-to-many table )
followers
comments
And in home, I do this query to get all followers' pictures.
SELECT users.username, pictures.link, comments.comment, boards.title
FROM boards_pictures, pictures, followers, users, comments, boards
WHERE ( boards_pictures.id_user = followers.id_following )
AND ( boards_pictures.id_picture = pictures.id )
AND ( followers.id_user = $_session['userid'] )
AND ( users.id = followers.id_following )
AND ( comments.picture_id = pictures.id )
AND ( boards.id = boards_pictures.boards_id )
Is there a way to avoid this complex query ( a JOIN with 6 tables ) ?