If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query output

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-15-10, 03:50
Pawan Kumar Pawan Kumar is offline
Registered User
 
Join Date: Mar 2008
Posts: 120
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
Reply With Quote
  #2 (permalink)  
Old 07-15-10, 06:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-15-10, 08:52
Pawan Kumar Pawan Kumar is offline
Registered User
 
Join Date: Mar 2008
Posts: 120
by creating procedure or function?if yes what will be logic?
__________________
Regards
Pawan Kumar
Reply With Quote
  #4 (permalink)  
Old 07-15-10, 09:54
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On