0

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.

Hecke29
  • 766
  • 6
  • 18
user1847437
  • 213
  • 1
  • 3
  • 12
  • Possible duplicate of [How to delete from multiple tables in MySQL?](http://stackoverflow.com/questions/3331992/how-to-delete-from-multiple-tables-in-mysql) – Hecke29 Nov 26 '15 at 09:04

3 Answers3

3

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
nagiyevel
  • 397
  • 3
  • 16
0

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
Parth Chavda
  • 1,819
  • 1
  • 23
  • 30
0

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";

user1847437
  • 213
  • 1
  • 3
  • 12