onedumbcoder Posted April 2, 2009 Share Posted April 2, 2009 How can I do something like this: insert into a(1,2,3,4,5,6) values((Select a,b,c from b WHERE id=1),"he","hy","hu") Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/ Share on other sites More sharing options...
fenway Posted April 2, 2009 Share Posted April 2, 2009 Huh? What do you want the records to look like in the end? Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/#findComment-799339 Share on other sites More sharing options...
onedumbcoder Posted April 2, 2009 Author Share Posted April 2, 2009 lets say I want to insert into table a six values, 3 of those values need to come from table b. so is there a way I can do this? in my example insert into a(1,2,3,4,5,6) values((Select a,b,c from b WHERE id=1),"he","hy","hu") I want (Select a,b,c from b WHERE id=1) to be treated as three values if possible, so it would ultimately translate values((Select a,b,c from b WHERE id=1),"he","hy","hu") as values(a,b,c,"he","hy","hu") Huh? What do you want the records to look like in the end? Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/#findComment-799543 Share on other sites More sharing options...
fenway Posted April 2, 2009 Share Posted April 2, 2009 I'm sorry I still don't understand... 1..6 refer to column offset?? Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/#findComment-799642 Share on other sites More sharing options...
onedumbcoder Posted April 2, 2009 Author Share Posted April 2, 2009 1-6 are just examples, lets say I have a table food with the fields name, id, date, creator, country, size so i want to make an insertion insert into food(name,id,date,creator,country,size) values((SELECT name,id,date FROM food WHERE id=3),"mike","usa","5") Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/#findComment-799666 Share on other sites More sharing options...
Zane Posted April 2, 2009 Share Posted April 2, 2009 I believe he wants to INSERT on SELECT. pretty much setting a SELECT query as a variable and using that to INSERT. show your table layout...all of it and then describe what you're doing. Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/#findComment-799669 Share on other sites More sharing options...
onedumbcoder Posted April 2, 2009 Author Share Posted April 2, 2009 Thanks zanus that is what I needed. Another question you know how there is INSERT INTO a(b) VALUES© WHERE NOT EXIST (SELECT id FROM ww WHERE id=1) can I do INSERT INTO a(b) VALUES© WHERE EXIST (SELECT id FROM ww WHERE id=1) Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/#findComment-799702 Share on other sites More sharing options...
fenway Posted April 3, 2009 Share Posted April 3, 2009 it's "exists", but yes. Quote Link to comment https://forums.phpfreaks.com/topic/152177-insert-into-one-table-using-info-from-another/#findComment-800296 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.