Jump to content

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.