【问题标题】:PSQL error ambigous column name when doing multi join statment执行多连接语句时 PSQL 错误列名不明确
【发布时间】:2022-01-23 17:05:57
【问题描述】:

我正在尝试以某种方式解决我的 PSQL 查询中的错误 ambiguous origin_type column name

查询

SELECT
    *
FROM
    "message"
    INNER JOIN "member" ON "member"."id" = "message"."member_id"
    INNER JOIN "conversation" ON "conversation"."id" = "message"."conversation_id"
WHERE
    "message_type" in('USER_MESSAGE')
    AND "origin_type" in('CONSENTEE_RECIPIENT')
    AND "origin_type" in('CONSENTEE')

我有 2 个具有相同名称的列,需要一种方法来避免此错误,但由于此时我不实用,我被阻止,因为不知道解决此问题的更好方法。

我尝试使用别名但没有成功

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    您应该使用"member"."origin_type""conversation"."origin_type""message"."origin_type" 而不仅仅是"origin_type",具体取决于您需要哪个表的origin_type

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 2013-03-26
      • 1970-01-01
      • 1970-01-01
      • 2014-02-25
      相关资源
      最近更新 更多