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

  • Home
  • SEARCH
  • 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 9259239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:36:27+00:00 2026-06-18T12:36:27+00:00

Suppose we have table with below information id name level Parent_id 1 A 1

  • 0

Suppose we have table with below information

id  name  level   Parent_id
1   A     1       ---
2   B     1       ----
3   C     2       1
4   D     2       2
5   E     3       3
6   F     3       4
7   G     4       5
8   H     4       5

i want the result in this format.

id  L1Name   L2 Name  L3 Name  L4Name
1   A        -        -        -
2   B        -        -        -    
3   A        C        -        -
4   B        D        -        -    
5   A        C        E        -
6   B        D        F        -
7   A        C        E        G
8   A        C        E        H

i want this result in mysql. we can find this in oracle by using Connect by prior. How about in mysql.please help.

  • 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-18T12:36:28+00:00Added an answer on June 18, 2026 at 12:36 pm

    you may looking for this

         select id , L1Name,   L2Name , L3Name , L4Name
         from (
             select id ,
             if(level =1 , name , '--') L1Name ,
             if(level =2 , name , '--') L2Name ,
             if(level =3 , name , '--') L3Name ,
             if(level =4 , name , '--') L4Name 
             from Table1
             )t
    

    DEMO HERE

    EDIT :

    try this

     SELECT id, L1Name,   L2Name , L3Name , L4Name
     FROM (
         SELECT id,
         IF(id in(1,3,5,7), 'A' , 'B') L1Name ,
         IF(id in(3,5,7) , 'C' , if(id in(1,2), '-', 'D')) L2Name ,
         IF(id in(5,7),'E',if(id in(1,2,3,4), '-', 'F')) L3Name ,
         IF(id =7 , 'G' , if(id in(1,2,3,4,5,6), '-', 'H')) L4Name 
         FROM Table1
     )t
    

    SQL DEMO HERE

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

Sidebar

Related Questions

Suppose I have this table: id | name | city ------------------ 1 | n1
Suppose I have a table, Foo, that looks like this: ID | Name |
Suppose I have this database table (some sample code below) that stores the relationship
I have data in a mysql table in long / tall format (described below)
Hi Suppose I have a table as below, I want to update the cat
Suppose I have a table view, and I want to implement something like this:
Suppose I have table Person table Employee, which inherits Person. I want to get
Suppose I have this table parent | child 1 2 1 3 2 4
Suppose that I have a database table that contains information on cities across the
Suppose I have a table called device as below: device_id(field) 123asf15fas 456g4fd45ww 7861fassd45 I

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.