-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ohhh you're close. A little tweak, and it works. Here's what I came up with:

INSERT INTO myTable
   (owner, name)
   SELECT id as "owner", 'myName' as "name"
   FROM users where username='myUserName';

I think if you omit the (owner, name), it thinks you want to fill the whole 
table, so by doing it this way you can specify only what you want to change.

Thanks for your help, Ernest!

- -Evan



On Monday 16 December 2002 12:13 am, you wrote:
> At 09:01 16.12.2002, Evan Nemerson said:
> --------------------[snip]--------------------
>
> >Anyways, my question is rather simple- how do I do an INSERT using a
> >subquery?
> >I want something like this- only one that works:
> >
> >INSERT INTO myTable
> >SET owner=(SELECT id FROM users WHERE username='myUsername');
>
> --------------------[snip]--------------------
>
> INSERT INTO myTable
>    SELECT id as "owner" FROM users where username='myUsername';
>
> other columns, not selected from source table:
>
> INSERT INTO myTable
>    SELECT id as "owner", 92 as "data1", 'hello world' as "data2"
>    FROM users where username='myUsername';
>
> should do it (untested on mySQL)

- -- 
Cats are intended to teach us that not everything in nature has a function.

- -Garrison Keillor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9/Y+w/rncFku1MdIRAtjFAJ9k8CaAVyHxe3Rdubo0cXPYMMP14gCfdZoN
/AXg9bAvjtt+xWCJMmY8r3E=
=byql
-----END PGP SIGNATURE-----


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to