我正在尝试将此查询与两个表连接在一起
select comments.*,username,title
from comments INNER JOIN users ON comments.user_id = users.user_id
INNER JOIN posts ON comments.post_id = posts.post_id;
返回的结果为column reference "username" is ambiguous
列的格式应为table.column
选择评论。*,用户名,标题
应该是
select comments.*,YOUR_TABLE.username,YOUR_TABLE.title
SELECT comments.*,users.username,title
FROM comments INNER JOIN users ON comments.user_id = users.user_id
INNER JOIN posts ON comments.post_id = posts.post_id;
请注意上面查询中的users.username
。
顺便说一句,您不应在多个表中都有列username
。您可能需要研究“标准化”数据。