New records since last query in MySQL View

二次信任 提交于 2019-12-25 03:59:24

问题


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:

  1. 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.

  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!