Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this MySQL Delete command getting an error?

Tags:

mysql

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?

like image 983
zeckdude Avatar asked Apr 28 '16 06:04

zeckdude


2 Answers

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
like image 156
Ankit Agrawal Avatar answered Nov 15 '22 00:11

Ankit Agrawal


You need to provide the table name which you want to delete like

DELETE h FROM hotel h
LEFT JOIN user_hotel uh ON h.hotel_id = uh.hotel_id
WHERE uh.user_hotel_id IS NULL
like image 21
Rahul Tripathi Avatar answered Nov 15 '22 00:11

Rahul Tripathi