根据所提供的ERD /图表,我在连接表方面需要帮助。我确实从一点开始做起,但是加入其他表格时遇到了问题。 这是我到目前为止所做的
SELECT first_name, last_name, username, post_title, comment_content
FROM profile_info p
JOIN club_member cm ON p.member_username = cm.username
JOIN blog_post bp ON cm.username = bp.member_username
JOIN post_comment pc ON bp.post_id = pc.post_id;
我想加入POST_PROP,TAG_MEMBER_W_INTEREST和INTEREST。但是我对如何做到这一点感到很困惑。请有人帮忙。下图是这样的:
此外,很抱歉,我无法发布链接以外的其他链接,因为我没有声望点。如果有人可以编辑此ID,请感激。谢谢。
更新:我能够加入5个表,现在剩下两个表POST_PROP和POST_COMMENT
--Profile info -> Club member -> Blog post -> TAG MEMBER INTEREST->INTEREST
SELECT first_name, last_name, username, post_title,interest_tag
FROM profile_info p
JOIN club_member cm ON p.member_username = cm.username
JOIN blog_post bp ON cm.username = bp.member_username
JOIN tag_member_w_interest tg ON cm.username= tg.member_username
JOIN interest i ON tg.interest_id = i.interest_id;
答案 0 :(得分:1)
似乎您需要添加
JOIN post_comment pc ON pc.member_username = cm.username
JOIN post_prop pp ON pp.member_username = cm.username
并通过绑定member_username
表的club_member
列获得以下SQL select语句
SELECT first_name, last_name, username, post_title, interest_tag
FROM profile_info p
JOIN club_member cm ON p.member_username = cm.username
JOIN blog_post bp ON cm.username = bp.member_username
JOIN tag_member_w_interest tg ON cm.username = tg.member_username
JOIN interest i ON tg.interest_id = i.interest_id
JOIN post_comment pc ON pc.member_username = cm.username
JOIN post_prop pp ON pp.member_username = cm.username;