Jump to content

comparing rows to find updated cells


mameha

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/132223-comparing-rows-to-find-updated-cells/
Share on other sites

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  ;D

You should get a row for every id that has at least one column updated, and a NULL value for not updated values

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.