Re: SQL question

From: Date: Wed, 31 Jan 2001 12:45:32 +0000
Subject: Re: SQL question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37470@lists.php.net to get a copy of this message
"John LYC" <john@edlabs.com> wrote in message news:3A765FF8.71ED43D5@edlabs.com... > hi all, > > does mysql support this? > > select * from tablename where id in (select id from table2 where cond) > > thanks > No. MySQL does not support so-called sub-selects. Here's an easy workaround in PHP: $result = mysql_query("SELECT id FROM table2 WHERE cond"); $idlist = array(); while($row = mysql_fetch_assoc($result)) { $idlist[] = $row[id]; } $result = mysql_query("SELECT id FROM table1 WHERE id IN(" . implode(", ", $idlist) . ")"); Making sure $idlist actually contains at least one item (if it doesn't the second query will fail) is left as an exercise to the reader. -- - Daniel Grace <http://dewin.oldbattery.com/> "Space may be the final frontier but its made in a Hollywood basement." - Red Hot Chili Peppers - Californication

« previous php.general (#37470) next »