Jump to content

Need Help


jana

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?
Link to comment
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.
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.