Hi all! I am having a "problem" with some SELECT statements to MySQL together with Perl, and I hope that anyone of you gurus here might give me a push in the right direction.
Since I currently only have a modem connection, I can't subscribe to this list and therefore I would be grateful if replies were sent directly to me at: [EMAIL PROTECTED] Now to the problem. I am currently using code like this (selects are shortened a little): $sth = $dbh->prepare ("SELECT DISTINCT col1 FROM t1, t2 ... WHERE ..."); $sth->execute($variable); while ($col1 = $sth->fetchrow_hashref ()) { $sub1 = $dbh->prepare ("SELECT sub1col1, sub1col2 ... FROM ... WHERE col1 = ? AND ..."); $sub1->execute($col1); while ($sub1result = $sub1->fetchrow_hashref ()) { ... do stuff with query result ... } $sub2 = $dbh->prepare ("SELECT sub2col1, sub2col2 ... FROM ... WHERE col1 = ? AND ..."); $sub2->execute($col1); ... } To put it in "plain speaking" what I am doing is that I am executing several SELECT statements within tha while loop with variables based upon the result of the first SELECT. It is working, but it seems as a little "over done" and slow approach. I have tried to "merge" all queries (the "first" as well as those in the while loop") into one SELECT statement, but I don't know how to handle the output, since I get so many rows and the data is "mixed". Let's say that the "first" statement returns 50 rows and "sub1" returns another 40 rows and "sub2" returns 60 rows. When doing as I do, the data is easily delt with, but when issuing it as only one query I get like 2000 rows. To further complicate things I sometimes need to issue another SELECT statement with variables based on one of the "sub queries", thus using another while loop within the running while loop. Is there any way that I can do this easier, without using SELECT statements in while loops? I am not a guru at this, so please be gentle to me.. :-) Patrik Birgersson [EMAIL PROTECTED] --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php