Jump to content


Photo

Need Help


  • Please log in to reply
4 replies to this topic

#1 jana

jana
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationIndia

Posted 17 October 2006 - 05:09 AM

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?
Jana

#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 17 October 2006 - 07:34 AM

the MySQL manual wants to be your friend, you know:

INSERT ... SELECT syntax

looks like you'd want something like:

INSERT INTO test1 (e_id, e_name)
  SELECT test2.e_id, test2.e_name
  FROM test2 WHERE test2.e_id > 3

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.

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 17 October 2006 - 03:50 PM

In fact, that's precisely the correct way to handle this.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 18 October 2006 - 04:18 AM

it's always nice to garner occasional support from the resident MySQL god :).

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 October 2006 - 04:11 PM

it's always nice to garner occasional support from the resident MySQL god :).

God may be a bit of an overstatement... but I'll settle for demi-god :-D
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users