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

时间:2015-02-23 15:29:37

标签: android sql sqlite inner-join

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

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:

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

2 个答案:

答案 0 :(得分:4)

您使用statemachines两次。一旦进入JOIN子句,一次进入FROM。

命名其中一个:

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

答案 1 :(得分:2)

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