【问题标题】:Ambiguous column name, yet use "." to specify table列名不明确,但使用“.”指定表
【发布时间】:2015-04-24 23:32:27
【问题描述】:

当以下查询发送到我的数据库时:

SELECT statemachines.statemachinename, 
states.statename, 
actionhandlers.actionhandler, 
actions.value, actions.sourcename 
FROM actions, actionhandlers, states, statemachines 
INNER JOIN rules ON (actions.rule_id AND rules.rule_id) 
INNER JOIN actionhandlers ON (actions.actionhandler AND actionhandlers.actionhandler) 
INNER JOIN states ON (states.state_id AND actions.state_id) 
INNER JOIN statemachines ON (states.statemachinename AND statemachines.statemachinename) 
WHERE (rules.eventname = 'PIR') AND (statemachines.currentstate = states.state_id)

返回如下错误:

 android.database.sqlite.SQLiteException: ambiguous column name: statemachines.statemachinename (code 1): , while compiling:

我不知道该怎么做,我的所有其他查询都有效。

【问题讨论】:

    标签: android sql sqlite inner-join


    【解决方案1】:

    你使用了两次statemachines。一次在 JOIN 子句中,一次在 FROM 中。

    说出其中一个:

    ...
    FROM actions, actionhandlers, states, statemachines AS statemachines1
    ...
    

    【讨论】:

    • 它不识别它是相同的状态机,我可以删除我的 from 子句中的状态机吗?
    • 我想我现在明白了,我只需要在 from 中声明一个表,其他表就会在它们集中在一起时被发现(通过内部连接)
    【解决方案2】:

    简化:FROM actions, actionhandlers, states, statemachines => FROM actions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多