payon Posted June 29, 2013 Share Posted June 29, 2013 (edited) 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? Edited June 29, 2013 by payon Quote Link to comment 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 Quote Link to comment 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.