Seems like this delete query should work, but it doesn't. What am I missing?

delete from calendar_sequence where id=(select id from calendar_sequence where date='2015-06-30' AND end_date='2015-06-30')

The error I get is: "You can't specify target table 'calendar_sequence' for update in FROM clause."

What do I need to change?
Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Why are you getting the id first.  Just do:
DELETE FROM `calendar_sequence` where `date`='2015-06-30' AND `end_date`='2015-06-30' LIMIT 1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Why can't you just do this
DELETE FROM calendar_sequence 
WHERE  DATE='2015-06-30' AND end_date='2015-06-30'

Open in new window

The second select is going to return a bunch of id's where date and end_date match those values and you are going to delete all ids in that set - so why not shortcut the process and go straight to the where clause.
Ray PaseurCommented:
Remember that DELETE, like all SQL statements applies to every row that matches the WHERE clause.  If you want to have better control over the deletions, you might consider additional subclauses for WHERE.
Bruce GustPHP DeveloperAuthor Commented:
Sometimes you just need another set of eyes on the thing, you know? Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.