合并SQL语句
我有 3 个表(关注、发帖、用户)
关注有 2 个字段 -> profile_id、following_id
帖子有 3 个字段 -> post_id, profile_id, content
users 有3个字段-> profile_id、first_name、last_name
我想要匹配的 follow.profile_id 值为 1。
当我运行下面的 SQL 语句时,我迈出了获取正确数据的第一步。但是,我现在想要将此结果集的 posts.profile_id 与用户表进行匹配,以便同时显示所有列出的帖子的每个名称(名字和姓氏)。
感谢您的帮助! :)
前任:
SELECT *
FROM follows
JOIN postings ON follows.following_id = postings.profile_id
WHERE follows.profile_id = 1
I have 3 tables (follows, postings, users)
follows has 2 fields -> profile_id , following_id
postings has 3 fields -> post_id, profile_id, content
users has 3 fields -> profile_id, first_name, last_name
I have a follows.profile_id value of 1 that I want to match against.
When I run the SQL statement below I get the 1st step in obtaining the correct data. However, I now want to match the postings.profile_id of this resulting set against the users table so each of the names (first and last name) are displayed as well for all the listed postings.
Thank you for your help! :)
Ex:
SELECT *
FROM follows
JOIN postings ON follows.following_id = postings.profile_id
WHERE follows.profile_id = 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用:
use:
使用:
Use:
似乎很容易将连接扩展到另一个表...也许我遗漏了问题的某些部分!
Seems easy enough to extend the join to another table... maybe I am missing some part of the question!