Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167212

Bunching a group of notifications

I have a notifications table with me:

+----+------+--------+--------+------------+
| ID | User | Object | Action | TimeStamp  |
+----+------+--------+--------+------------+
|  1 |    1 |      3 | Like   | 2014-05-01 |
|  2 |    2 |      3 | Like   | 2014-05-01 |
|  3 |    3 |      3 | Like   | 2014-05-01 |
|  4 |    3 |      5 | Share  | 2014-05-01 |
+----+------+--------+--------+------------+

If you can see, the Users 1, 2, 3 have liked the same object 3. In the Notifications window, if we just give a simple SELECT query, it shows like this:

But since the action has been done on the same object, I would like to bunch or group the notifications like this:

I have the following questions:

  1. How do I group / bunch the notifications?
  2. Is my notifications table schema the right one?

Upvotes: 1

Views: 74

Answers (1)

juergen d
juergen d

Reputation: 204884

select object, action, group_concat(`user`) as users
from notifications
group by object, action

Upvotes: 1

Related Questions