2019-05-02

MySQL - Split string into groups and retrieve 'n' number of groups

select
SUBSTRING_INDEX( v, ',', 1) as first_part
, SUBSTRING_INDEX( v, ',', 2) as first_and_second_parts
, SUBSTRING_INDEX( v, ',', 3) as first_through_third_parts
, SUBSTRING_INDEX( v, ',', 4) as first_through_fourth_parts
, SUBSTRING_INDEX( v, ',', 5) as first_through_fifth_parts
, SUBSTRING_INDEX( v, ',', 0) as no_parts
, SUBSTRING_INDEX( v, ',', 100) as all_parts
from
(select 'apple, bbq, celery, daisies, ebony' as v) as n1
;

No comments:

Post a Comment