What is the opposite of GROUP_CONCAT in MySQL?

You could use a query like this: SELECT id, SUBSTRING_INDEX(SUBSTRING_INDEX(colors, ‘,’, n.digit+1), ‘,’, -1) color FROM colors INNER JOIN (SELECT 0 digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) n ON LENGTH(REPLACE(colors, ‘,’ , ”)) <= LENGTH(colors)-n.digit ORDER BY id, n.digit Please see fiddle here. Please notice that this query …

Read more

Concatenate and group multiple rows in Oracle [duplicate]

Consider using LISTAGG function in case you’re on 11g: select grp, listagg(name,’,’) within group( order by name ) from name_table group by grp sqlFiddle upd: In case you’re not, consider using analytics: select grp, ltrim(max(sys_connect_by_path (name, ‘,’ )), ‘,’) scbp from (select name, grp, row_number() over (partition by grp order by name) rn from tab …

Read more

How do I concatenate strings from a subquery into a single row in MySQL?

by using the GROUP_CONCAT() function and a GROUP BY call. here’s an example query SELECT p.package_id, p.package_name, p.price, GROUP_CONCAT(pz.zone_id SEPARATOR ‘,’) as zone_list FROM package p LEFT JOIN package_zone pz ON p.package_id = pz.package_id GROUP BY p.package_id you should still be able to order by zone_id s (or zone_list), and instead of using LIKE, you …

Read more

GROUP_CONCAT with limit

One somewhat hacky way to do it is to post-process the result of GROUP_CONCAT: substring_index(group_concat(s.title SEPARATOR ‘,’), ‘,’, 3) as skills Of course this assumes that your skill names don’t contain commas and that their amount is reasonably small. fiddle A feature request for GROUP_CONCAT to support an explicit LIMIT clause is unfortunately still not …

Read more