0

I am trying to increment 'sellingDate' field that's in 'company' table.

UPDATE company 
   SET sellingDate = ((SELECT DATE_ADD((SELECT sellingDate 
                                          FROM company 
                                         WHERE cid = '35'), INTERVAL 1 DAY))) 
 WHERE cid = '35';

This query gives me an error saying:

Error Code: 1093
You can't specify target table 'company' for update in FROM clause

What am I doing wrong here?

1
  • Thank you everyone for response. Commented Jan 26, 2011 at 6:04

4 Answers 4

2

Use:

UPDATE company 
   SET sellingDate = DATE_ADD(sellingDate, INTERVAL 1 DAY)
 WHERE cid = '35'

MySQL doesn't allow a subquery in an UPDATE statement against the same table, but the subquery is unnecessary for this example. For some odd reason a self-join in an UPDATE statement won't return the 1093 error though it's the same logic.

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

UPDATE company SET sellingDate = DATE_ADD(sellingDate, INTERVAL 1 DAY) WHERE cid = '35';

Comments

0

You can not use sub query from same table which you are updating However you can achieve same by this query

UPDATE company SET sellingDate=DATE_ADD(sellingDate, INTERVAL 1 DAY) WHERE cid = '35';

Comments

0

Why do you need to use a nested query to increment this field?

UPDATE company SET sellingDate = DATE_ADD(sellingDate, INTERVAL 1 DAY) WHERE cid = '35';

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.