I have a dataset like
("group_1" , uuid , other, columns),
("group_1" , uuid , other, columns),
("group_1" , uuid , other, columns),
("group_2" , uuid , other, columns),
("group_2" , uuid , other, columns),
("group_3" , uuid , other, columns),
("group_3" , uuid , other, columns),
That is within a table declared like:
CREATE TABLE sample(
group TEXT,
id TEXT,
Other,
columns,
PRIMARY KEY( group , id)
);
What I want to do is fetching a list of list of data, that all data with same group name will be in the same row. What do I mean is:
[
[("group_1" , uuid , other, columns),
("group_1" , uuid , other, columns),
("group_1" , uuid , other, columns)],
[("group_2" , uuid , other, columns),
("group_2" , uuid , other, columns)],
[("group_3" , uuid , other, columns),
("group_3" , uuid , other, columns)],
]
That is a list of list of rows with the same group name.
I don't know if is it possible to reach such a result using database built-in functions like GROUP BY
or not, because when I try it, it only returns the first row of same group name rows in the following query:
SELECT * FROM sample GROUP BY group;
I am also interested to know if there is a better way of achiving this result?
PS: The reason why don't I use group keys to fetch data like SELECT * FROM sample WHERE group = 'group_1';
is because I don't know the group names( there are thousands of them) and I only want fetch a bunch of data with different group names and put them in same group names and make a list of lists with same group name of them.