![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Apr 2004
Location: Montreal
Posts: 799
|
Recursive Query with MySQL ?
Basicaly I need to fetch the root parent of any object child. (could be as low as 25 level deep into the tree structure.)
Is there a way to do it in mysql ? I've seen it in SQLServer with the "With" statement. heres my db columns: dbID idParent idChild 1 2 1 3 2 4 2 5 4 6 For example, I need to query to return 1 if I look for idChild = 6 thanks
__________________
I have nothing to advertise ... yet. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Bollocks
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
|
Think you would need a stored procedure for that, but not sure as I've never done one in MySQL.
__________________
Interserver unmanaged AMD Ryzen servers from $73.00 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Aug 2002
Posts: 1,888
|
Last I checked, the WITH clause was not supported in MySQL.
__________________
I do things skype:themodF |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Apr 2004
Location: Montreal
Posts: 799
|
It's not ... and this is why I'm having trouble.
__________________
I have nothing to advertise ... yet. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: May 2008
Posts: 3,406
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Join Date: Jan 2007
Location: Vienna, Austria
Posts: 374
|
Google Nested set model
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
Quote:
Regardless, it sounds like you real problem is that the DB design sucks and you'd just have to do multiple queries.. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Join Date: Apr 2004
Location: Montreal
Posts: 799
|
Problem ain't speed ... it's getting root parent...
__________________
I have nothing to advertise ... yet. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Quote:
Are you trying to do something like: Code:
idParent* = 1 | ---> idChild => 2,3,4,5,6 #so on and so forth All in all, more information is needed. *I'm not including additional idParent values as of now in order to get an exact idea of what you're trying to accomplish. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Sep 2002
Posts: 135
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
Confirmed User
Join Date: Apr 2004
Location: Montreal
Posts: 799
|
Quote:
Sorry if my explanations weren't clear. (The html kind of scrw up my table)
__________________
I have nothing to advertise ... yet. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Quote:
@qw12er - Now let me ask.. is this in php? |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
Confirmed User
Join Date: Apr 2004
Location: Montreal
Posts: 799
|
php 5.3 -yup
__________________
I have nothing to advertise ... yet. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Have you tried pulling up the entire query and using maybe a foreach or while loop?
Can it be a simple matter of say... Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Additionally, if you just want to get all idChild values and match them with idParent values, you can modify the above $query to:
$query = sprintf('SELECT idParent, idChild FROM dbtable'); Then change the while line to: while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //do stuff echo $row['idChild']; echo $row['idParent']; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 | |
Confirmed User
Join Date: Apr 2004
Location: Montreal
Posts: 799
|
Quote:
Yeah that's is sort of what I did but this solutions isn't clean as it could be. (makes way to much query to DB for nothing)
__________________
I have nothing to advertise ... yet. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
Confirmed User
Join Date: Dec 2005
Posts: 271
|
Derp de derp, ta teetley tum
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
Confirmed User
Join Date: Jan 2007
Location: Vienna, Austria
Posts: 374
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |