Results 1 to 4 of 4

Thread: query output

  1. #1
    Join Date
    Mar 2008
    Posts
    136

    Unanswered: query output

    Hi All,
    There is one table and have self reference . I want some output from that table as per some condition.

    Table A---
    Records Like--
    PKAID FKAID
    1 NULL
    2 1
    3 1
    4 3
    5 2
    6 NULL
    7 5

    If I give input PKID=1 then output must be like below as I need only PKAID..

    PKAID
    1
    2
    3
    4
    5
    7

    If I give input PKID=3 then output must be like below as I need only PKAID..

    PKAID
    3
    4

    If I give input PKID=6 then output must be like below as I need only PKAID..

    PKAID
    6

    It seems here will be used recursive type query or pl/sql but how not getting
    Please suggest some solution for the same...

    Regards
    Regards
    Pawan Kumar

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Pawan Kumar View Post
    It seems here will be used recursive type query or pl/sql but how not getting
    there is no recursive functionality in mysql

    there is no pl/sql language in mysql
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2008
    Posts
    136
    by creating procedure or function?if yes what will be logic?
    Regards
    Pawan Kumar

  4. #4
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    run the same query until you find there are no more child rows. Meaning:

    Code:
    select fkaid from table where pkaid =&pk
    
    select fkaid from table where pkaid = "the fkaid you just got"
    and keep running this til there are no rows returned.
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •