Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
SQL Group By field. Grouping items by split row code

I have table like this

Name Code
John 0
Sam 01
Jack 011
Bill 02
Parent 1
Some1 11
Some2 111
Some3 112
Some4 1111

Is that posible group data in SQL like this?

[
    {
        Name: 'John',
        Code: '0',
        children: [
            {
                Name: 'Sam',
                Code: '01',
                children: [
                    { Name: 'Jack', Code: '011' }
                ]
            },
            {
                Name: 'Bill',
                Code: '02'
            }
        ]
    },
    {
        Name: 'Parent',
        Code: '1',
        children: [
            {
                Name: 'Some1',
                Code: '11',
                children: [
                    {
                        Name: 'Some2',
                        Code: '111',
                        children: [
                            { Name: 'Some4', Colde: '1111' }
                        ]
                    },
                    { Name: 'Some3', Code: '112' }
                ],
            },
        ]
    }
]

Or is it better to do it on JS?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!