在查询通知系统中遇到麻烦

时间:2016-10-16 13:23:32

标签: sql sql-server-2012

我在Db设计上阅读了很多关于类似facebook(不太复杂)的通知系统(帖子溢出流)的帖子。最后我做了两张桌子。 这是两个表,Notification和NotificationStatus。每个新帖子都会更新通知表。当任何用户读取/查看或将其标记为已读时,将更新NotificationStatus表。在NotificationStatus表中,我保留读取或查看通知的用户的记录。现在我无法进行查询。

Notification
=========================================================
(p.k)Id | User_Id | Post_Id | CreateDate | NotificationType 

NotificationStatus
=========================================================
Id | (f.k)Notification_Id | User_Id | IsRead (boolean) 

这是myQuery: -

SELECT Notification.Time, Notification.Post_Id, Notification.User_Id
FROM  Notification 
where  Notification.User_Id in (check my freind list ) and 
Notification.User_Id not in (select * from NotificationStatus)

1 个答案:

答案 0 :(得分:0)

这是您了解阅读帖子的用户的方法。

SELECT 
   n.Time, 
   n.Post_Id, 
   n.User_Id
FROM
   Notification n
INNER JOIN
   NotificationStatus s ON  s.Notification_Id = n.Id
WHERE
   s.IsRead = 'True'

如果要在特定的用户列表上过滤此查询,我们需要知道您如何传递用户...即逗号分隔列表,表变量等。