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. To get son and all grandsons

To get son and all grandsons

Scheduled Pinned Locked Moved Database
database
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
    VB Net Developer
    wrote on last edited by
    #1

    parent son A B A C A D D E D F D G G I G J i blank j blank b blank c balnk I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..

    P G 2 Replies Last reply
    0
    • V VB Net Developer

      parent son A B A C A D D E D F D G G I G J i blank j blank b blank c balnk I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      VB.Net Developer wrote:

      I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..

      Very good. What have you tried so far? Plus, what database is this query in. We don't do homework for you, and we don't do your thinking for you. We do help you if you've tried something and can't get it to work. Hint - if you are using SQL Server, take a look at Common Table Expressions (CTEs) to accomplish this.

      Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      • V VB Net Developer

        parent son A B A C A D D E D F D G G I G J i blank j blank b blank c balnk I need a query to get son and grandson, grandgrand sons (till Entire generation) …. Of ‘A’…..

        G Offline
        G Offline
        Grampa Simpson
        wrote on last edited by
        #3

        Trying to be a bit more helpful But the solution has to do with CTEs, at least if your using SQL Server as this is not standard SQL: with tmp(parent, son) as ( select tab.parent, tab.son from tab where tab.parent='A' union all select tmp.super, tab.son from tmp join tab on tmp.son=tab.parent Beware of loops! In that case you need to introduce a recursion counter or a condition that restricts son<>'A'.

        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