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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:40:05+00:00 2026-06-12T11:40:05+00:00

Table Structure: I Tried this: select Id, Name from Color where ParentId=4 UNION select

  • 0

Table Structure:

enter image description here

I Tried this:

select Id, Name from Color where ParentId=4
UNION
select Id, Name from Color where ParentId=(select Id from Color where ParentId=4)

Above approach is static in this case I have to know all the Ids. I’m looking something dynamic approach since I would have only Color’s ParentId value.

As example: For ParentId=4 there are two records; Name Blue and Red their Id is 6 and 10 respectively. Now here, I need to get all the records where Id 6 and 10.

  • 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-12T11:40:06+00:00Added an answer on June 12, 2026 at 11:40 am

    Try this:

    ;WITH cte
    AS
    (
        SELECT Id, Name, ParentId  
        FROM Color 
        WHERE ParentId = @parentIdValue
        UNION ALL
        SELECT c2.Id, c2.Name, c2.ParentId  
        FROM cte c1
        INNER JOIN Color c2 ON c2.ParentId = c1.Id
    )
    SELECT * FROM cte;
    

    Live Demo

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

Sidebar

Related Questions

i have table with following structure, name (type: TEXT) price (type: INT) color (type:
I have this database structure: sites id | name 1 | Site 1 2
This is my table structure fName Friend's Name [Varchar] fUID Friend's ID [Int] UID
I have two tables, first table structure (data) : -id -name -title -mail -source_id
I have a table reply of which structure is following: Id name parent_id ...
i have a table of the following structure id name field1 field2 field3 1
I really surprised when I tried below code in MySQL: SELECT * FROM table
Hello I have a table structure like this products_id | model_num | master_model_num 1
Table structure goes something like this: Table: Purchasers Columns: id | organization | city
I have the following table structure: ID | fname | lname | street |

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.