decouple sensor 10 from location (where it was coupled to in meaning_id = 21): INSERT INTO meaning ( location_id, sensor_id, first_log_id, prev_meaning_id ) VALUES ( NULL, 10, ( SELECT MAX(log_id) + 1 FROM log ), 21) couple uncoupled sensor 10 to location (starting NOW) INSERT INTO meaning ( location_id, sensor_id, first_log_id ) VALUES ( 8, 16, ( SELECT MAX(log_id) + 1 FROM log ) )