List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:October 5 2002 6:06pm
Subject:Re: mysql: multiple SELECTs with INSERT or UPDATE??
View as plain text  
At 15:54 +0200 10/5/02, Mirza wrote:
>Hi,
>
>    i am inserting data in a mysql table like this:
>    INSERT INTO mytable1
>    (bu_main_id)
>       SELECT main_id FROM mytable2
>       WHERE username=\"$username\"
>
>    that's ok.
>   
>    but now i would like to insert 2 values (bu_main_id and status), and i
>    would like to know, is it possible to use 2 or more SELECTs
>    together with an INSERT, for example:
>
>    INSERT INTO mytable1
>    (bu_main_id, status)
>       SELECT main_id FROM mytable2
>       WHERE username="$username",
>       SELECT config_mode FROM mytable3
>       WHERE config_value="status"

If you have MySQL 4.x, try using a UNION.   If you don't, then can
you just issue two separate INSERT INTO ... SELECT statements?

>    my 2nd question, is it possible to use UPDATE and (mulstiple)
>    SELECTs together
>    i.e.:
>
>    UPDATE mytable
>    SET xxx = (SELECT xxx from mytable2 WHERE config="yyy") ...

As of 4.0.2, yes, but not with that syntax. It would be something
like this:

UPDATE mytable, mytable2 SET mytable.xxx = mytable2.xxx
WHERE mytable2.config='yyy';

>   
>    thanx
>
>    Mirza

Thread
mysql: multiple SELECTs with INSERT or UPDATE??Mirza5 Oct
  • Re: mysql: multiple SELECTs with INSERT or UPDATE??Paul DuBois5 Oct
  • Re: mysql: multiple SELECTs with INSERT or UPDATE??John Ragan6 Oct