Anyone could tell me what is wrong with the following mysql query?
DELETE FROM table1 as A, table2 as B WHERE A.delivery_status = '3' AND
A.delivered_on < '2015-11-26' AND A.delivery_id = B.delivery_id
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
as A, table2 as B WHERE A.delivery_status = '3' AND A.delivered_on '
at line
I also tried < DATE('2015-11-26')
because delivered_on
is a datetime
field, with no success.
try this
DELETE FROM table1 A, table2 B WHERE A.delivery_status = '3' AND
A.delivered_on < '2015-11-26' AND A.delivery_id = B.delivery_id
Table aliases in a multiple-table DELETE should be declared only in the table_references part of the statement. Elsewhere, alias references are permitted but not alias declarations. You must type:
DELETE A,B FROM table1 as A, table2 as B WHERE A.delivery_status = '3' AND
A.delivered_on < '2015-11-26' AND A.delivery_id = B.delivery_id
This works fine for me:
DELETE table1 FROM table1 LEFT JOIN table2 ON table1.delivery_id = table2.delivery_id WHEREtable1.delivery_status = '3' AND table2.delivered_on < DATE($today) AND table1.delivery_id = table2.delivery_id";