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