Sample Header Ad - 728x90

Group concat up to a maximum number of rows in SQLite

0 votes
1 answer
827 views
I want to group concat several rows, but only up to maximum number of x rows. Here is the code without the maximum
create table if not exists csvs (
  id integer,
  csv text
);

insert into csvs (id, csv)
values
  (1, 'one'),
  (1, 'two'),
  (2, 'three'),
  (2, 'four'),
  (2, 'five'),
  (2, 'six');

select id, group_concat(csv)
from csvs
group by id;
This yields: id | group_concat(csv) ---|--- 1|one,two 2|three,four,five,six What I want to achieve is this (so a maximum of 3 entries per row): id | group_concat(csv) ---|--- 1|one,two 2|three,four,five 2|six Is this possible?
Asked by adius (113 rep)
Jul 27, 2022, 06:49 PM
Last activity: Jul 29, 2022, 12:14 PM