不明确的列名,但使用“。”指定 table

Ambiguous column name, yet use "." to specify table

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

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:

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

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

说出其中之一:

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

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