payon Posted June 29, 2013 Share Posted June 29, 2013 Hello, I need your help. I have two different tables, where I would like to copy coumns values from a specific column in table 1 to a apsecific column in table 2. But it should copy with condition. E.g. Tabe1 id | date | --------------- 0 | 23-05-2013 1 | 10-04-2013 2 | 02-01-2013 4 | 04-04-2013 40 | 04-03-2013 Table2 id | date | --------------- 1 | 0-0-0000 2 | 0-0-0000 3 | 0-0-0000 4 | 0-0-0000 40 | 0-0-0000 So I would like to copy column Table1.data to column Table2.data where Table1.id = Table2.id. The problem might be, that both tables have different id entries. But all ids which are in table1 and table2 should be used for replacement of the associated data field. So the result should be Table2 id | date | --------------- 1 | 10-04-2013 2 | 02-01-2013 3 | 0-0-0000 4 | 04-04-2013 40 | 04-03-2013 Is this possible with a MySQL statement? Link to comment https://forums.phpfreaks.com/topic/279698-copy-columns-data-with-condition/ Share on other sites More sharing options...
Barand Posted June 30, 2013 Share Posted June 30, 2013 UPDATE table1 INNER JOIN table2 USING (id) SET table2.date = table1.date Also change your date fields to type DATE, format YYYY-MM-DD. Your format is useless in a database Link to comment https://forums.phpfreaks.com/topic/279698-copy-columns-data-with-condition/#findComment-1438665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.