Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:01:43+00:00 2026-05-23T21:01:43+00:00

OK, so I do suck at MySQL, but here is basically what I want

  • 0

OK, so I do suck at MySQL, but here is basically what I want to do:

delete from course_plan_relationships
where course_plan_relationships.id not in ( 
    select course_plan_relationships.id
    from daily_plans inner join 
    course_plan_relationships on daily_plans.id=course_plan_relationships.daily_plan_id
);

To give you an idea of what’s happening, I’ll show you the subquery and its result:

mysql> select course_plan_relationships.id from daily_plans inner join 
course_plan_relationships on daily_plans.id=course_plan_relationships.daily_plan_id;
+----+
| id |
+----+
|  1 |
| 13 |
+----+

So basically, I want to delete all items in course_plan_relationships, where its id field is not in that table I generated there in the subquery.

The error I get is:

ERROR 1093 (HY000): You can’t specify target table
‘course_plan_relationships’ for update in FROM clause

What I’ve basically gotten is that for some reason MySQL won’t let you DELETE or UPDATE based on a sub-query involving the same table.

That’s fine, and here’s a supposed workaround:
http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/

But its for UPDATE and doesn’t use the “in” syntax.

I’m really new to this stuff so any help would be super appreciated. I haven’t had any luck using the “AS blahothertablename” kind of syntax (keep getting syntax errors), and I also can’t figure out how to store the initial subquery as a temporary result (again, syntax errors).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:01:44+00:00Added an answer on May 23, 2026 at 9:01 pm

    Using multi-table syntax in the delete, you don’t need the sub-query:

    DELETE course_plan_relationships
    FROM course_plan_relationships LEFT JOIN
    daily_plans ON course_plan_relationships.daily_plan_id = daily_plans.id
    WHERE daily_plans.id IS NULL;
    

    http://dev.mysql.com/doc/refman/5.0/en/delete.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have not done this before, so obviously I suck at it. Here 64 pixels
Hey. First question here, probably extremely lame, but I totally suck in regular expressions
I suck at php, and cant find the error here. The script gets 2
I'm a developer and I suck at SQL:) Please help me out here. I'd
I know maybe this is a stupid question, But i suck at sql But
I need to suck data from stdin and create a object. The incoming data
To be honest, I suck at regex so much, I would use RegexBuddy, but
I'm not going to lie. I suck at writing htaccess rules. I'm ok with
Well now at my company we are switching from MySQL 5 to PostgreSQL 8.4
I suck at rewrite rules so.. pity me >_> I want to get these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.