Below query gives me “#1093 – You can’t specify target table ‘reservation_seats’ for update in FROM clause” error.
DELETE
FROM reservation_seats
WHERE id IN ( SELECT id
FROM reservation_seats
WHERE reservation_id NOT IN ( SELECT id FROM reservation)
);
Table Structure :
reservation_seats - id,reservation_id,seat_no
reservation - id,txn_id,name......
reservation table(id) column is used as the foreign in the reservation_seats table.
(reservation.id = reservation_seats.reservation_id )
Can you please tell me why is that and how to fix it?
Thanks
In MySQL you can’t delete from the table you are selecting from. Try
to trick MySQL to do it anyway. BTW this could be made simpler like this