abdfahim Posted November 14, 2010 Share Posted November 14, 2010 Hi, I have 2 tables t1 and t2. They have identical columns only except t1 has one extra column x1. What I want is to dump data from t2 to t1, and in the x1 column, put the person's name (get from SESSION). So, I want the best optimized way to do something like mysql_query("INSERT INTO `t1` '".$usename."' , SELECT * FROM `shareltp`"); //which obviously doesn't work Plz help Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/ Share on other sites More sharing options...
BlueSkyIS Posted November 14, 2010 Share Posted November 14, 2010 specify columns $sql = "INSERT INTO t1 (col1, col2, col3, col4, col5) SELECT col1, col2, col3, col4, col5 FROM t2"; mysql_query($sql) or die(mysql_error() . " IN $sql"); Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134129 Share on other sites More sharing options...
abdfahim Posted November 15, 2010 Author Share Posted November 15, 2010 well, my problem is the extra column in t1 table (say col0). How to incorporate that? Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134405 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 well, my problem is the extra column in t1 table (say col0). How to incorporate that? Are you asking how you take 7 columns and insert them into a 6 column table? You can't. If you're asking how to ignore a specific column, read the previous reply more carefully. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134425 Share on other sites More sharing options...
abdfahim Posted November 15, 2010 Author Share Posted November 15, 2010 well, my problem is the extra column in t1 table (say col0). How to incorporate that? Are you asking how you take 7 columns and insert them into a 6 column table? You can't. If you're asking how to ignore a specific column, read the previous reply more carefully. -Dan I haven't ask either of them .. I want to take 6 column from a table and insert them in a 7 column table whereas filling up the 7th column with a constant (don't say to use default coz that constant will vary with the user) Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134431 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 INSERT INTO t1 (col1, col2, col3, col4, col5, col6, col7) SELECT *, SomeFunction(t2.someColumn, 'Make The Data Here') FROM t2 -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134538 Share on other sites More sharing options...
litebearer Posted November 15, 2010 Share Posted November 15, 2010 you may need to 1. copy the six columns. 2. do an immediate update for that record to add the new column data Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134546 Share on other sites More sharing options...
ManiacDan Posted November 15, 2010 Share Posted November 15, 2010 If you can't calculate the last column's value on the fly (like in my query) then just pull all the data into a scripting language and make one huge insert out of it. You haven't said how many rows or how you're going to get this mystery column's value. Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134549 Share on other sites More sharing options...
abdfahim Posted November 15, 2010 Author Share Posted November 15, 2010 You haven't said how many rows or how you're going to get this mystery column's value. it'll be the date string read from a text file at the moment of insert Quote Link to comment https://forums.phpfreaks.com/topic/218648-dump-data-from-one-table-to-another/#findComment-1134550 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.