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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -