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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:12:00+00:00 2026-06-18T04:12:00+00:00

I have a standard hierarchical table ID/PID and I need to find (boolean) if

  • 0

I have a standard hierarchical table ID/PID and I need to find (boolean) if some child belongs to some ID. Is there a way to do this within mysql?

ID   PID
------------
1     0          <- root
...   ...
...   ... 
...   ...
7     1
...   ...
16    1
...   ...
4     0
...   ...
22    16
25    16

Is there a way to know if child node 22 belongs to node 1 ? I’m asking because I want to implement some Delete procedure, where node 1 is my Recycle. All deletes belongs to 1 will be deleted permanently and all other delete will have PID replaced, so temporarily belongs now to 1.

Thanks very much in advance,

  • 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-18T04:12:01+00:00Added an answer on June 18, 2026 at 4:12 am

    Based on Hierarchical queries in MySQL :

    SET @x := 22;
    SET @y := 0;
    
    select 'yes' as x_comes_from_y 
    from dual
    where @y in
    (
     SELECT  @id :=
            (
            SELECT  pid
            FROM    h
            WHERE   id = @id
            ) AS nodes
     FROM    (
            SELECT  @id := @x
            ) vars
     STRAIGHT_JOIN
            h
     WHERE   @id IS NOT NULL
    );
    

    Test it.

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

Sidebar

Related Questions

I have a standard form array in PHP like this. I need to account
I have standard ASP.NET 4 application. Inside this application there are also few razor
I've heard they have standard GUI guideline, but I can't seem to find a
I have a standard table: I want to use jQuery to reformat the table,
I have a simple hierarchic model whit a Person and RunningScore as child. this
I have standard multi-level menu like this one: <ul id=nav> <li><a href=#>Home</a></li> <li><a href=#>Dropdown</a>
I have a web application that have standard form authentication declared, like this: <login-config>
I have been looking at Javascript templating engines trying to find a way to
I have standard page in Salesforce. I cannot modify this page. But what I
We have this standard color in our application: <SolidColorBrush x:Key=ThemeColor Color=#FF95BBF0/> We are trying

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.