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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:05:19+00:00 2026-05-27T01:05:19+00:00

I have a 9 table db set up like this. TableA acct_id TableB tabB_id

  • 0

I have a 9 table db set up like this.

TableA
acct_id

TableB
tabB_id
tabA_id_fk

TableC
tabC_id
tabB_id_fk

TableD
tabD_id
tabB_id_fk

TableE
tabE_id
tabB_id_fk

I’m sure you see the pattern by now. The second table reference the first and all others reference the second. The second table (TableB) has seven tables which reference it through foreign keys. One of the tables is one-to-many with TableB, let’s say TableD. I want to delete the corresponding rows in all the tables with one query. I’ve searched for awhile and can’t find an answer. Here is the SQL statement I’m using.

DELETE FROM photos, location, contacts, messages, stats, viewed_by, ethnicity,  profile, members
USING photos INNER JOIN location 
INNER JOIN contacts 
INNER JOIN messages 
INNER JOIN stats 
INNER JOIN viewed_by 
INNER JOIN ethnicity 
INNER JOIN profile 
INNER JOIN members 
WHERE photos.profile_id_fk = profile.profile_id 
AND location.profile_id_fk = profile.profile_id 
AND stats.profile_id_fk = profile.profile_id 
AND viewed_by.profile_id_fk = profile.profile_id 
AND ethnicity.profile_id_fk = profile.profile_id 
AND profile.member_id_fk = members.member_id 
AND members.member_id=?

The query does not return any errors but it also doesn’t delete any rows. What could be the problem?

Should I just use nine seperate delete queries, one for each table?

Thanks everyone.

  • 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-27T01:05:20+00:00Added an answer on May 27, 2026 at 1:05 am

    My first answer assumes InnoDB. This answer does this for MyISAM.
    delete in mysql

    > desc parent; desc child_1; desc child_2;
    +-------+--------------+------+-----+---------+-------+
    | Field | Type         | Null | Key | Default | Extra |
    +-------+--------------+------+-----+---------+-------+
    | id    | int(11)      | NO   | PRI | NULL    |       |
    | name  | varchar(100) | YES  |     | NULL    |       |
    +-------+--------------+------+-----+---------+-------+
    2 rows in set (0.00 sec)
    
    +--------------+--------------+------+-----+---------+-------+
    | Field        | Type         | Null | Key | Default | Extra |
    +--------------+--------------+------+-----+---------+-------+
    | id           | int(11)      | NO   | PRI | NULL    |       |
    | parent_id_fk | int(11)      | YES  |     | NULL    |       |
    | name         | varchar(100) | YES  |     | NULL    |       |
    +--------------+--------------+------+-----+---------+-------+
    3 rows in set (0.00 sec)
    
    +--------------+--------------+------+-----+---------+-------+
    | Field        | Type         | Null | Key | Default | Extra |
    +--------------+--------------+------+-----+---------+-------+
    | id           | int(11)      | NO   | PRI | NULL    |       |
    | parent_id_fk | int(11)      | YES  |     | NULL    |       |
    | name         | varchar(100) | YES  |     | NULL    |       |
    +--------------+--------------+------+-----+---------+-------+
    3 rows in set (0.01 sec)
    
    > select * from parent; select * from child_1; select * from child_2;
    +----+------------+
    | id | name       |
    +----+------------+
    |  1 | Andreas    |
    |  2 | Wederbrand |
    +----+------------+
    2 rows in set (0.00 sec)
    
    +----+--------------+-----------+
    | id | parent_id_fk | name      |
    +----+--------------+-----------+
    |  1 |            1 | Child 1 1 |
    |  2 |            1 | Child 1 2 |
    |  3 |            2 | Child 2 1 |
    |  4 |            2 | Child 2 2 |
    +----+--------------+-----------+
    4 rows in set (0.00 sec)
    
    +----+--------------+-----------+
    | id | parent_id_fk | name      |
    +----+--------------+-----------+
    |  1 |            1 | Child 1 1 |
    |  2 |            1 | Child 1 2 |
    |  3 |            2 | Child 2 1 |
    |  4 |            2 | Child 2 2 |
    +----+--------------+-----------+
    4 rows in set (0.00 sec)
    
    > delete p, c1, c2 from parent p, child_1 c1, child_2 c2 where p.id = c1.parent_id_fk and p.id = c2.parent_id_fk and p.id = 2;
    Query OK, 5 rows affected (0.33 sec)
    

    Your query could be correct, I don’t have your tables, but test with

    DELETE photos, location, contacts, messages, stats, viewed_by, ethnicity,  profile, members
    FROM photos 
    INNER JOIN location 
    INNER JOIN contacts 
    INNER JOIN messages 
    INNER JOIN stats 
    INNER JOIN viewed_by 
    INNER JOIN ethnicity 
    INNER JOIN profile 
    INNER JOIN members 
    WHERE photos.profile_id_fk = profile.profile_id 
    AND location.profile_id_fk = profile.profile_id 
    AND stats.profile_id_fk = profile.profile_id 
    AND viewed_by.profile_id_fk = profile.profile_id 
    AND ethnicity.profile_id_fk = profile.profile_id 
    AND profile.member_id_fk = members.member_id 
    AND members.member_id=?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my table columns set like this: likes(id, like_message, timestamp) id is the
I have a SQL table set that looks like this create table foo (
Let's say I have a table of users set up like this: CREATE TABLE
I have a temp table set up like this: Type Rate TotalCost ---- ----
I have a table like this- event (id,name,date) I need a result set like
I have a table set up like this Project Category Date Hours Proj1 test
I have a mysql table set up like this id | refference_id | data
I need to have MySQL query like this one: UPDATE table_name SET 1 =
I have 2 tables set up like this (irrelevant rows omitted): > product -
I have a table and I would like to be able to set up

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.