Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to get this nested level output

How to get this nested level output

Scheduled Pinned Locked Moved Database
tutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VenkataRamana Gali
    wrote on last edited by
    #1

    There are two tables, NAMES (ID INT IDENTITY (1,1), NAME VARCHAR(255)) and RELATIONSHIPS ( NAMEID INT , PARENT _ NAMEID INT ) linked via NAMES.ID = RELATIONSHIPS.NAMEID and where top-most name has a PARENT _ NAMEID = 0. Show a nested list of names including LEVEL , NAMEID and NAME , where LEVEL indicates the nest level (or depth) from the top, as indicated in the expected output (below). NAMES table content: ================== ID NAME 1 Frank 2 Jo 3 Mary 4 Peter 5 Amy RELATIONSHIPS table content: ========================== NAMEID PARENT _ NAMEID 1 0 2 1 3 2 4 1 5 2 Expected Output: =================== In the expected output, please note The sequence of the output, in which child elements appear immediately beneath their respective parent elements. LEVEL ID NAME 0 1 Frank 1 2 Jo 2 5 Amy 2 3 Mary 1 4 Peter any sounds please...

    Ramana

    S W 2 Replies Last reply
    0
    • V VenkataRamana Gali

      There are two tables, NAMES (ID INT IDENTITY (1,1), NAME VARCHAR(255)) and RELATIONSHIPS ( NAMEID INT , PARENT _ NAMEID INT ) linked via NAMES.ID = RELATIONSHIPS.NAMEID and where top-most name has a PARENT _ NAMEID = 0. Show a nested list of names including LEVEL , NAMEID and NAME , where LEVEL indicates the nest level (or depth) from the top, as indicated in the expected output (below). NAMES table content: ================== ID NAME 1 Frank 2 Jo 3 Mary 4 Peter 5 Amy RELATIONSHIPS table content: ========================== NAMEID PARENT _ NAMEID 1 0 2 1 3 2 4 1 5 2 Expected Output: =================== In the expected output, please note The sequence of the output, in which child elements appear immediately beneath their respective parent elements. LEVEL ID NAME 0 1 Frank 1 2 Jo 2 5 Amy 2 3 Mary 1 4 Peter any sounds please...

      Ramana

      S Offline
      S Offline
      ScottM1
      wrote on last edited by
      #2

      This looks like a homework assignment. First try and do it before you ask for help otherwise it defeats the purpose of it.

      1 Reply Last reply
      0
      • V VenkataRamana Gali

        There are two tables, NAMES (ID INT IDENTITY (1,1), NAME VARCHAR(255)) and RELATIONSHIPS ( NAMEID INT , PARENT _ NAMEID INT ) linked via NAMES.ID = RELATIONSHIPS.NAMEID and where top-most name has a PARENT _ NAMEID = 0. Show a nested list of names including LEVEL , NAMEID and NAME , where LEVEL indicates the nest level (or depth) from the top, as indicated in the expected output (below). NAMES table content: ================== ID NAME 1 Frank 2 Jo 3 Mary 4 Peter 5 Amy RELATIONSHIPS table content: ========================== NAMEID PARENT _ NAMEID 1 0 2 1 3 2 4 1 5 2 Expected Output: =================== In the expected output, please note The sequence of the output, in which child elements appear immediately beneath their respective parent elements. LEVEL ID NAME 0 1 Frank 1 2 Jo 2 5 Amy 2 3 Mary 1 4 Peter any sounds please...

        Ramana

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #3

        Have a look at: Recursive Queries Using Common Table Expressions[^]

        The need to optimize rises from a bad design. My articles[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups