Reputation: 9778
We have a daily data feed. I need to determine what rows are new. (It's a long story, but there are no record numbers for the rows and they aren't going to be any.) We need to be able to identify which rows are new since the previous data feed. The file comes in as JSON and I have been putting it into a MySQL TABLE for other purposes.
How do I take yesterday's TABLE and compare it to today's TABLE, and to display those rows which have been added since yesterday? Can all this be done in MySQL, or do I need to do this with the help of PHP?
If I was doing this in PHP, I'm thinking I would search today's TABLE with yesterday's TABLE, and flag (an added column) in today's TABLE called NEW with a "N" when it's found. "Y" would be the default which means the row is new. Then using MySQL do a select where new="Y" and this would display the new fields. Is this how to do this? Am I overlooking a better method? Thanks!
Upvotes: 0
Views: 1335
Reputation: 3226
If you actually have two separate tables (which is how it sounds from your description, but is odd) and aren't comparing literally the same table, you can
SELECT partnumber FROm Today_table where partnumber not in (select partnumber from Yesterday_table)
Upvotes: 1