Don Laknath
Don Laknath

Reputation: 55

Notification System

I'm coding a social community. I want to add a notification system. I can make a table like

id | from | to| msg | time | seen

This is a good way for comments/likes notifications, but I want to notify users when group posts are updated.So if I use this table, then I have to add more than 100 or 1000 rows if group has more than 100,1000 members.

My current solution is adding a new col call 'grops'. But if user is in more than 20 groups, then I have to select 20 groups using OR.

EG:

id  |  from  |  to  |  group  |  message 
1      -1       -1       3        test1
2      -1       -1       2        test2
3      -1       -1       1        test3
4       5        3      -1        test4


SELECT * FROM `notifications` WHERE `to` = '3' OR `group` = '1' OR `group` = '2' OR `group` = '3' ... 

Is there any other way to do this or am I doing it correctly ?

-Thank you :)

Upvotes: 0

Views: 234

Answers (1)

Imesha Sudasingha
Imesha Sudasingha

Reputation: 3570

You can use the in clause. you don't have to write 20 OR statements.

SELECT * FROM `notifications` WHERE `to` = '3' OR `group` in ('1','2','3',....,'20');

Upvotes: 1

Related Questions