Reputation: 167212
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:
1
has liked Object 3
. 2 mins ago2
has liked Object 3
. 2 mins ago3
has liked Object 3
. 2 mins ago3
has shared Object 5
. 2 mins agoBut since the action has been done on the same object, I would like to bunch or group the notifications like this:
1
, 2
, 3
has liked Object 3
. 2 mins ago3
has shared Object 5
. 2 mins agoI have the following questions:
notifications
table schema the right one?Upvotes: 1
Views: 74
Reputation: 204884
select object, action, group_concat(`user`) as users
from notifications
group by object, action
Upvotes: 1