我正在设计一个像 pinterest 这样的网站(用于学习),我想知道我必须在主页上做什么查询才能显示用户的流。
我创建了这 6 个表:
users
boards
pictures
boards_pictures ( many-to-many table )
followers
comments
在家里,我做这个查询来获取所有关注者的照片。
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 )
有没有办法避免这种复杂的查询(6 个表的 JOIN)?