greatest n per group - Array slicing / group_concat limiting in MySQL -
let's have table:
j --- 1 2 3 4 b 5 b 6 b 7 b 8 b 9
obvoiusly select a, group_concat(b separator ',') group a give me
1,2,3,4 b 5,6,7,8,9
but if want limited number of results, 2, example:
1,2 b 5,6
any ideas?
best way use substring_index() , group_concat().
select i, substring_index( group_concat(j), ',', 2) mytable group i; you don't have know length of j field here.
Comments
Post a Comment