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.

1

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.