fesan Posted March 24, 2009 Share Posted March 24, 2009 Hello.... I want to copy a whole row from one table to another. I found the INSERT INTO .. SELECT function, but i want to "simplify" it if possible. as i understood i have to write out every field that i want to insert to, but i want to insert in to every field. it there a way to use * in this function? I want to do this because the table I'm inserting to is a history table... so when ever a field in the mail table is updated a copy of the old one is inserted in to the history table.... Quote Link to comment https://forums.phpfreaks.com/topic/150860-insert-into-select/ Share on other sites More sharing options...
Mchl Posted March 24, 2009 Share Posted March 24, 2009 http://dev.mysql.com/doc/refman/5.1/en/insert-select.html The (col_name,...) is in [], which means it is optional. I never tried it, but I think it should work as long as both tables have exactly same columns in exactly same order. Quote Link to comment https://forums.phpfreaks.com/topic/150860-insert-into-select/#findComment-792478 Share on other sites More sharing options...
fesan Posted March 24, 2009 Author Share Posted March 24, 2009 ok.... well, i have added one field to the history table. this is because i want to keep the id from the old table and make a new id in the history table.... I'll try it out and see how it goes! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/150860-insert-into-select/#findComment-792487 Share on other sites More sharing options...
fesan Posted March 24, 2009 Author Share Posted March 24, 2009 Now I've solved out some issues but i still get a error: Column count doesn't match value count at row 1 I've deleted the extra id field, and made the two tables exactly the same.... Could this be the Auto increment i have on my main table that is failing? Because the ID field in my history table is not an auto increment field. Quote Link to comment https://forums.phpfreaks.com/topic/150860-insert-into-select/#findComment-792497 Share on other sites More sharing options...
fenway Posted March 27, 2009 Share Posted March 27, 2009 We can't guess your statement or your table structures. Quote Link to comment https://forums.phpfreaks.com/topic/150860-insert-into-select/#findComment-795298 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.