Lit Aiy Lit Aiy - 5 months ago 11
MySQL Question

What is causing "Not unique table/alias" error in mysql?

I have this mysql query below.

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'


I am at a loss what caused the error
Lookup Error - MySQL Database Error: Not unique table/alias: 'data_records'
. I clearly have data_records table in my database.

Answer

You are not join sensors but two time data_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'