我在下面有这个mysql查询。
UPDATE data_records
INNER JOIN doors
ON (sensors.gateway_id = doors.id)
INNER JOIN data_records
ON (data_records.sensor_id = sensors.id)
SET data_records.value=1
WHERE doors.addr='FFA'
我不知道导致错误Lookup Error - MySQL Database Error: Not unique table/alias: 'data_records'
的原因。我的数据库中显然有data_records表。
答案 0 :(得分:4)
您有> <some magic command>
some context
的两个联接。我想你打算:
data_records
您的查询引用UPDATE data_records dr INNER JOIN
sensors s
ON dr.sensor_id = s.id INNER JOIN
doors d
ON s.gateway_id = d.id
SET dr.value = 1
WHERE d.addr = 'FFA';
但未在sensors
子句中定义。
另请注意,我添加了表别名,因此查询更容易编写和阅读。
答案 1 :(得分:2)
您不是加入传感器,而是两次数据_recods
UPDATE data_records
INNER JOIN doors ON (sensors.gateway_id = doors.id)
INNER JOIN sensors ON (data_records.sensor_id = sensors.id)
SET data_records.value=1
WHERE doors.addr='FFA'
答案 2 :(得分:0)
您犯了一个错误,并使用了data_records
两次而不是sensors
表,或者您只是想将第二个data_records
别名为sensors
。无论哪种方式都是错误的。
第一个选项:
UPDATE data_records
INNER JOIN doors
ON (sensors.gateway_id = doors.id)
INNER JOIN sensors
ON (data_records.sensor_id = sensors.id)
SET data_records.value=1
WHERE doors.addr='FFA'
第二个:
UPDATE data_records
INNER JOIN doors
ON (sensors.gateway_id = doors.id)
INNER JOIN data_records sensors
ON (data_records.sensor_id = sensors.id)
SET data_records.value=1
WHERE doors.addr='FFA'