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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:56:55+00:00 2026-05-15T18:56:55+00:00

I am not frequent SQL coder, I use it only for a simple tasks.

  • 0

I am not frequent SQL coder, I use it only for a simple tasks. I want to find a solution for a probably simple problem.

I have two tables:

Master_tbl [fields: ID, Plant, Detail_Group_ID]

and

Detail_tbl [fields: ID, Group_ID, Plant]

With such example data:

Master_tbl:

ID  Plant   Detail_Group_ID

1    Tree       1

2    Flower     2

Detail_tbl:

ID  Group_ID    Plant

1   1            Oak

2   1            Apple

3   1            Spruce

4   1            Maple

5   2            Tulip

6   2            Rose

7   2            Violet

8   2            Orchid

I want to make SQL statement to put two tables in one (in master/detail way):

The result table should display data in Treeview like fashion, where master fields are like parent nodes and detail fields like child nodes (see outcome below). I am not really sure, if this could be mastered via SQL…

Plant

Tree

Oak

Apple

Spruce

Maple

Flower

Tulip

Rose

Violet

Orchid

Thanx 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-05-15T18:56:56+00:00Added an answer on May 15, 2026 at 6:56 pm
    SELECT Master_tbl.Plant as `Group`, Detail_tbl.Plant as Plant FROM Master_tbl
    JOIN Detail_tbl on Master_tbl.Detail_Group_ID=Detail_tbl.Group_ID
    

    That will give you output like:

    Group   Plant
    Tree    Oak
    Tree    Apple
    Tree    Spruce
    Tree    Maple
    Flower  Tulip
    Flower  Rose
    Flower  Violet
    Flower  Orchid
    

    Here’s another option:

    SELECT Master_tbl.Plant as `Group`, group_concat(Detail_tbl.Plant) as Plants 
    FROM Master_tbl JOIN Detail_tbl on Master_tbl.Detail_Group_ID=Detail_tbl.Group_ID
    group by `Group`;
    

    The output is:

    +--------+--------------------------+
    | Group  | Plants                   |
    +--------+--------------------------+
    | Flower | Tulip,Rose,Violet,Orchid |
    | Tree   | Oak,Apple,Spruce,Maple   |
    +--------+--------------------------+
    

    It’s not necessarily the tree you wanted, but I think it’s as close as you can get. In everything I could find, I couldn’t find a way to get the tree output in one column like you posted. However, with these two queries, you can very easily parse the results based on the group.

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

Sidebar

Related Questions

I have an app that uses several prefixes and, while not frequent, it's also
My app has a not that frequent operation that is executed on the UI
This has to be a frequent question, but not on SO yet, so it
Not ever sure if it can be done, but is it possible to use
NOT USING A XML PARSER I want to get the contents of the XML
I'm not seeing something obvious re:caching strategies in rails. I have a prices table
I'm a frequent SQL Server Management Studio user. Sometimes I'm in situations where I
I have the following table in SQL Server: CREATE TABLE [dbo].[Users]( [Id] [int] IDENTITY(1,1)
I have frequent need to test that XML files are correct and need a
We have to develop an application like Google Draw, not exactly the same. The

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.