"John LYC" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> 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




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to