我不知道这是否是执行此操作的最佳方法,但是由于我没有别人的想法,所以我会这样做。我希望这个答案也能对其他人有所帮助。
我们有2张桌子
notification-----------------id (pk)useridnotification_type (for complexity like notifications for pictures, videos, apps etc.)notificationtimenotificationsRead--------------------id (pk) (i dont think this field is required, anyways)lasttime_readuserid
这个想法是从通知表中选择通知,并加入notificationsRead表,并检查最后读取的通知和ID>
Notificationid的行。并且每次打开通知页面时,都会更新notificationsRead表中的行。
我想查询未读通知的查询将是这样。
SELECt `userid`, `notification`, `time` from `notifications` `notificationsRead`WHERe `notifications`.`userid` IN ( ... query to get a list of friends ...) AND (`notifications`.`time` > ( SELECt `notificationsRead`.`lasttime_read` FROM `notificationsRead` WHERe `notificationsRead`.`userid` = ...$userid...))
上面的查询未选中。感谢@espais的db design的想法



