Jump to content

Archived

This topic is now archived and is closed to further replies.

jana

Need Help

Recommended Posts

i have two tabes as test1 and test2.

test1
(e_id, e_name)

test2
(e_id, e_name)

and i want to insert the values into test1 from test2.

can i do like this?

insert into test1 values("select e_id, e_name from test2 where e_id>3");

can anyone solve this?

Share this post


Link to post
Share on other sites
the MySQL manual wants to be your friend, you know:

[url=http://dev.mysql.com/doc/refman/5.0/en/insert-select.html]INSERT ... SELECT syntax[/url]

looks like you'd want something like:

[code]INSERT INTO test1 (e_id, e_name)
  SELECT test2.e_id, test2.e_name
  FROM test2 WHERE test2.e_id > 3[/code]

can't guarantee the two-column SELECT will work, but it's worth a shot.  it should probably work as long as you specify the column order in the INSERT INTO portion.

Share this post


Link to post
Share on other sites
In fact, that's precisely the correct way to handle this.

Share this post


Link to post
Share on other sites
it's always nice to garner occasional support from the resident MySQL god :).

Share this post


Link to post
Share on other sites
[quote author=akitchin link=topic=111736.msg453558#msg453558 date=1161145135]
it's always nice to garner occasional support from the resident MySQL god :).
[/quote]
God may be a bit of an overstatement... but I'll settle for demi-god :-D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.