我应该使用哪个连接?
假设我说一个名为:post 的表。另一张表是评论。
帖子和评论之间的关系是哪个评论属于一个帖子。而且一篇文章有很多评论。
那么,我想连接这两个表,我应该使用哪个连接?
Post
id
Comments
id
post_id
Let say I say a table called:post. Another table is comments.
And the relationship between post and comments is which comment belong to one post. And one post have many comments.
So, I want to join that two table, which join should I use??
Post
id
Comments
id
post_id
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您到底想要做什么,以及您的数据库模式有哪些外键。
一般来说,对于 1 对 N 的关系(1 个帖子有 N 个评论),您可以对帖子和评论进行
LEFT OUTER JOIN
,例如:It depends on what exactly you want to do, and what foreign keys your database schema has.
Generally, for a 1-to-N relationship (1 post has N comments) you do a
LEFT OUTER JOIN
of posts to comments, for example: