内部加入PostgreSQL

我正在尝试将此查询与两个表连接在一起

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

woshiriluobingcheng1 回答:内部加入PostgreSQL

列的格式应为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。您可能需要研究“标准化”数据。

本文链接:https://www.f2er.com/3136332.html

大家都在问