jana Posted October 17, 2006 Share Posted October 17, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/24175-need-help/ Share on other sites More sharing options...
akitchin Posted October 17, 2006 Share Posted October 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/24175-need-help/#findComment-109883 Share on other sites More sharing options...
fenway Posted October 17, 2006 Share Posted October 17, 2006 In fact, that's precisely the correct way to handle this. Quote Link to comment https://forums.phpfreaks.com/topic/24175-need-help/#findComment-110107 Share on other sites More sharing options...
akitchin Posted October 18, 2006 Share Posted October 18, 2006 it's always nice to garner occasional support from the resident MySQL god :). Quote Link to comment https://forums.phpfreaks.com/topic/24175-need-help/#findComment-110464 Share on other sites More sharing options...
fenway Posted October 19, 2006 Share Posted October 19, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/24175-need-help/#findComment-111368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.