mameha Posted November 11, 2008 Share Posted November 11, 2008 I have a table of data that should be updated every 3 hours by a new set of data. I put the new data into a new table, and now I want to compare the two tables to find what data has been updated. For example: OLD TABLE id | height | width 123 | 55 | 80 NEW TABLE id | height | width 123 | 65 | 80 As you can see, height has been updated to 65. Is there some query that can (1) find all rows that have been updated and (2) tell me which column was updated? Quote Link to comment https://forums.phpfreaks.com/topic/132223-comparing-rows-to-find-updated-cells/ Share on other sites More sharing options...
luca200 Posted November 11, 2008 Share Posted November 11, 2008 SELECT n.id, if(n.height != o.height, n.height, null) as height, if(n.width != o.width, n.width, null) as width from newtable n join oldtable o on n.id = o.id where (o.height != n.height or o.width != n.width) Not tested, just try it You should get a row for every id that has at least one column updated, and a NULL value for not updated values Quote Link to comment https://forums.phpfreaks.com/topic/132223-comparing-rows-to-find-updated-cells/#findComment-687621 Share on other sites More sharing options...
fenway Posted November 11, 2008 Share Posted November 11, 2008 Actually, you should jeft join and use IFNULL to decide. Quote Link to comment https://forums.phpfreaks.com/topic/132223-comparing-rows-to-find-updated-cells/#findComment-687874 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.