Merging notifications

1

I want to make a system of notifications that group together when they are the same type, as those of Facebook. For now I have the table with the following columns:

user_id (person receiving notification),

icon (Generally the profile photo of another user),

description (the description of the notification),

registry (record date),

seen (a Boolean that checks if the person has already viewed)

How do I create notifications? Well, this happens at the time the action is performed. For example, I click the Next button, under the function I register the notification, like this:

user_id : User id I followed,

icon : My profile picture,

description : Insanity started following you !,

registry : CURRENT_TIME (),

seen : 0

I have two main problems:

  • If I click the follow button multiple times, it will send multiple notifications.
  • The problem of grouping: If more than one person follows, let's suppose 1000 people do this, 1000 notifications will appear. How to group Facebook, for example: "Geraldo, Thiago and over 998 people have started following you!".
asked by anonymous 11.09.2016 / 23:11

1 answer

0

Use the GROUP BY clause, which is used to group (or aggregate) the rows of the table according to a criterion chosen by the user, and then a group function can be applied to each of the groups. Using GROUP BY can not select individual rows.

The example below determines the average wage for each job (JOB):

SELECT job, AVG(sal)
FROM emp
GROUP BY job;


JOB       AVG(SAL)               
--------- ----------
CLERK     1037,5                 
SALESMAN  1400                   
PRESIDENT 5000                   
MANAGER   2758,3 
ANALYST   3000                   

5 rows selected
    
22.09.2016 / 23:30