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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:43:34+00:00 2026-06-09T13:43:34+00:00

I have a table with, let’s say, the following columns: Name , Parent Name

  • 0

I have a table with, let’s say, the following columns:

Name , Parent Name, ID

Let’s also say that there are three entries where Parent Name is Null (meaning they are the top-most parent) – F_one, G_one, and H_one.

If I want to delete all the descendants of one of those parents (G_one, why not?) meaning all the children of G_one, all the children of those children, and the children of those, and so on all the way until the terminal level where, that row’s Name does not exist as a Parent Name for any other entry.

Is that possible to be done easily, maybe with a single query?

Bonus, is there a way to select all of the G_one lineage so I can manipulate it to my whim and will?

Can assume:
-No Children are shared among parents

Cannot assume:
-A discrete or even consistent number of sub-levels.

  • 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-06-09T13:43:36+00:00Added an answer on June 9, 2026 at 1:43 pm

    As @Marc B’s suggestion, a FORIEGN KEY with ON DELETE CASCADE would achieve this.

    If you haven’t one, you can add it now:

    1. If there is a UNIQUE constraint on Name (I assume the PRIMARY key os ID), skip thi sstep. If there ism’t one, create it:

      ALTER TABLE tableX
        ADD CONSTRAINT unique_Name
          UNIQUE (Name) ;
      
    2. If the previous step succeeded, add the FOREIGN KEY:

      ALTER TABLE tableX
        ADD CONSTRAINT fk_Name_ParentName
          FOREIGN KEY (ParentName)
             REFERENCES tableX (Name)
             ON UPDATE CASCADE
             ON DELETE CASCADE ;
      
    3. If the previous step succeeded, you can now delete your rows with one statement:

      DELETE
      FROM tableX
      WHERE ParentName = 'G_one' ;
      

      This should result in: Y rows affected.

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

Sidebar

Related Questions

Let's say I have table with following columns: id created_at The default sort on
Let's say I have a table called messages with the columns: id | from_id
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
Let say i have three table (post, wall, photo) post (id, post_uid, post_content, post_timestamp)
Let's say I have a table that represents a super class, students . And
Let's say I have table TabA with columns: col1 - primary key (but not
Let's say I have table [users] with the field [Name] and I've written a
let say i have one table, which have data like: name status bob single
Let's say I have a table called 'species' with 3 columns: 'Id', 'ancestorId' and
I have a table let's say in the form of: match(id, hometeam_id, awayteam_id) and

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.