Re: Query help needed

From: Date: Thu, 15 Jun 2000 09:11:11 +0000
Subject: Re: Query help needed
Groups: php.general 
Request: Send a blank email to php-general+get-1909@lists.php.net to get a copy of this message
Addressed to: "D u r r a n i" <durrani@comatindia.com> php-general@lists.php.net ** Reply to note from "D u r r a n i" <durrani@comatindia.com> Thu, 15 Jun 2000 10:20:13 +0530 > > > mysql> Select name from register where parant in ('Select name from = > register where parant =3D "Mumbai"') ; Empty set (0.00 sec) =20 > > 1. This fits in php-db@lists.php.net better than php-general. IMHO, they split the lists by subject for a reason. At least you did not post to all of them, thank you for that! 2. MySQL does not support nested queries. You will have to split it up into two SELECT operations, and combine the results of the first into the IN( ) for the second. Something like: (untested) # Get the list of names where parant = Mumbai $Result = mysql_Query( "SELECT name " . "FROM register " . "WHERE parant = 'Mumbai' " ); # Get the results and put them in an array ($Names) while( list( $Name ) = mysql_Retch_Row( $Result )) { $Names[] = $Name; } # Take the list of names from the array and put them in a # string like this name1', 'name2', 'name3 $NameList = join( "', '", $Names ); # Tell mysql you are done with the first result set mysql_free_result( $Result ); # Get the list of names from the IN() clause $Result = mysql_Query( "SELECT name " . "FROM register " . "WHERE parant in( '$NameList' ) " ); If the list of names was the ones listed in the comment above, the WHERE clause will look like this: WHERE parant in ( 'name1', 'name2', 'name3' ) Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.general (#1909) next »