zeckdude zeckdude - 7 months ago 12
SQL Question

Why is this MySQL Delete command getting an error?

I'm trying to run this MYSQL command:

DELETE FROM hotel h
LEFT JOIN user_hotel uh ON h.hotel_id = uh.hotel_id
WHERE uh.user_hotel_id IS NULL


It is returning this error:


1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'h LEFT JOIN user_hotel uh ON h.hotel_id = uh.hotel_id WHERE
uh.user_hotel_id I' at line 1


The command seems self-explanatory, so not sure what I'm getting wrong. Any ideas?

Answer

you are missing table_name those you want to delete

DELETE h FROM hotel h
LEFT JOIN user_hotel uh ON h.hotel_id = uh.hotel_id
WHERE uh.user_hotel_id IS NULL
Comments