prophecym Posted August 1, 2012 Share Posted August 1, 2012 Hi everyone, I am sure there's a way to do this. I just don't know how. Any help is appreciated. I have 2 tables that need to be compared based on their one particular field. Say this is the 'name' field. During the comparison of these two tables, it needs to find the same records. Then, change the data in the another field to something else. Table A Table B id | name | boolean name As you can see above, the name field needs to be compared. When it finds the same records, the 'boolean' field in the Table A needs to be changed whatever I set to. (If it is 1, change it to 2) I would love to know how to do this. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/266546-changing-the-data-after-comparison/ Share on other sites More sharing options...
Christian F. Posted August 1, 2012 Share Posted August 1, 2012 What you need is an UPDATE statement, with a WHERE clause to limit the rows updated to what you want. Something like this should work, though it might require you to join table B so try it on some test data first. UPDATE `table_a` AS a SET a.`boolean` = $Val WHERE `table_b`.`name` = a.`name` Another way of doing it is by using WHERE IN() and a subquery. A quick google search will give you lots of examples on how this is done. Quote Link to comment https://forums.phpfreaks.com/topic/266546-changing-the-data-after-comparison/#findComment-1365995 Share on other sites More sharing options...
prophecym Posted August 1, 2012 Author Share Posted August 1, 2012 I have a mind blank. I couldn't get this to work. And I couldn't find If it is not too much trouble, would you write down what exactly should I write down? Quote Link to comment https://forums.phpfreaks.com/topic/266546-changing-the-data-after-comparison/#findComment-1366089 Share on other sites More sharing options...
fenway Posted August 4, 2012 Share Posted August 4, 2012 You want to change a boolean field to "2"? Quote Link to comment https://forums.phpfreaks.com/topic/266546-changing-the-data-after-comparison/#findComment-1366812 Share on other sites More sharing options...
prophecym Posted August 10, 2012 Author Share Posted August 10, 2012 You want to change a boolean field to "2"? :confused: What was I thinking But I know that you know what I mean. Quote Link to comment https://forums.phpfreaks.com/topic/266546-changing-the-data-after-comparison/#findComment-1368285 Share on other sites More sharing options...
Barand Posted August 10, 2012 Share Posted August 10, 2012 UPDATE tableA a INNER JOIN tableB b ON a.name = b.name SET a.boolean = 2 WHERE a.boolean = 1 Quote Link to comment https://forums.phpfreaks.com/topic/266546-changing-the-data-after-comparison/#findComment-1368319 Share on other sites More sharing options...
prophecym Posted August 15, 2012 Author Share Posted August 15, 2012 UPDATE tableA a INNER JOIN tableB b ON a.name = b.name SET a.boolean = 2 WHERE a.boolean = 1 Thank you very much, you just saved me from a ton of work. Quote Link to comment https://forums.phpfreaks.com/topic/266546-changing-the-data-after-comparison/#findComment-1369739 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.