Answer the question
In order to leave comments, you need to log in
How to form a selection of unique objects in an array?
The table has a unique id, there is a user id , an additional type value and a value from 1 to 6 that he chose.
id | id_user | type | data
----+-----------+-------
1 | 1456 | action | 6
2 | 5812 | usual | 2
3 | 1456 | present | 1
4 | 1456 | present | 1
5 | 5812 | usual |2
6 | 7774 | present | 1
I need to make a selection so that I get the user id and an array with unique objects, i.e. no duplicate entries.
The output should be:
[
{
id_user: 1456,
data: [
{data: 6, type: action},
{data: 1, type: present}
],
},
{
id_user: 5812,
data: [
{data:2, type: usual}
]
},
{
id_user: 7774,
data: [
{data:1, type: present}
]
}
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question