问题
I am looking for a way to create a View that when queried will automatically only retrieve new records since the last query. My tables have a timestamp field for all entries, so for a simple example I can
SELECT * WHERE timestamp >= 'blah'
but I don't know how to determine what blah
should be from the last query. So if the View was queried at 11:00 and then again at 12:00, the query at 12:00 should only return records added since 11:00. And so on... This all needs to be accomplished in the View, the end user should simply be able to query the View and get the results.
Is this possible?
回答1:
There are two ways:
Store last access date time in database per user persistent session table, if you have one. On next view call to database, use the previous latest access time in the session to filter rows starting from.
Store last access date time in user virtual session at client environment. On every call to server, send last access date time as well. So that server uses it to filter rows starting from.
I prefer to use second option that process won't write any data in database tables.
来源:https://stackoverflow.com/questions/26096146/new-records-since-last-query-in-mysql-view