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 7521797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:20:01+00:00 2026-05-30T02:20:01+00:00

DELETE FROM table_a WHERE id IN( SELECT table_a.id AS id FROM table_a, table_b WHERE

  • 0
DELETE FROM table_a WHERE id IN(
    SELECT table_a.id AS id FROM table_a, table_b 
    WHERE table_a.object_id = 1 AND table_a.code = 'code' 
        AND table_a.code = table_b.code 
        AND table_b.id = table_a.b_id 
        AND table_b.table = 'testTable')

This is a (somewhat simplified) query I want MySQL to execute. I read on other pages of stackoverflow that this wasn’t supported and that it’s solvable by using JOINS. How could this be ‘transcribed’ to a query using JOINS? I find it hard to do so, because I’ve never tried creating DELETE queries with more than one table.

  • 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-30T02:20:03+00:00Added an answer on May 30, 2026 at 2:20 am

    You can’t delete from a table and reference the same table in a subquery — just a limitation of MySQL. Something like the following should work:

    DELETE FROM table_a 
    USING table_a
    INNER JOIN table_b
        ON table_a.code = table_b.code
        AND table_b.id = table_a.b_id
        AND table_b.table = 'testTable'
    WHERE table_a.object_id = 1 
        AND table_a.code = 'code' 
    

    The important part is USING. If you just join the two tables, you’ll delete records from both. USING tells MySQL to use these tables for processing, but only delete from the tables in the FROM clause.

    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

If I have a query like, DELETE FROM table WHERE datetime_field < '2008-01-01 00:00:00'
I want to delete a table from a sqlite3 db at certain times, i.e.
Normaly i would do a delete * from XXX but on this table thats
Here is my query: $query=Delete b Where Exists ( Select 1 From a Where
I just did a delete from table How do I roll back or undelete
delete from a A where a.ID = 132. The table A contains around 5000
How do you delete rows from a table, where a column contains a substring,
How can I delete a row from a table which it has been created
I wish to DELETE the data from a table before performing an INSERT INTO,
What's the best way to delete all rows from a table in sql but

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.