How can I genereate a string from the returns of a SELECT query in Mysql?
Please try this query:

select group_concat(foo_id separator ',') as ids from
(
select 
 case 
 when locate('-', foo_ids) &gt; 0 then 
  substr(foo_ids, 1, locate('-', foo_ids) - 1) 
 else foo_ids 
 end as foo_id
from foo_table
union all
select 
 case 
 when locate('-', foo_ids) &gt; 0 then 
  substr(foo_ids, (locate(foo_ids, '-') + 1), locate('-', foo_ids) - 1) 
 else null 
 end as foo_id
from foo_table
) t 
where foo_id is not null


http://sqlfiddle.com/#!2/ce1b0a/7