MySQL Select distinct values from same cell -
i have table following structure. problem have store multiple values in "functions" column. know practice should avoided searching solution on scenario.
id chapters functions
1 chapter 1 function 1 function 2 function 2 2 chapter 2 test 1 test 2 function 2
i searching mysql query output following
function 1 function 2 test 1 test 2
i have tried following query not work of course since treats contents of each cell whole.
select distinct functions chapters
i have tried solving problem in via php's array_unique function didn't work either.
since values seperated new line can use \n
escape sequences along substring_index function , inner join can achieve same
check below example
create table func ( id int, functions varchar(200)); insert func values (1, 'function 1 function 2 function 2'), (2, 'test 1 test 2 function 2');
query
select distinct substring_index(substring_index(func.functions, '\n', numbers.n), '\n', -1) result (select 1 n union select 2 union select 3 union select 4) numbers inner join func on char_length(func.functions) -char_length(replace(func.functions, '\n', ''))>=numbers.n-1 order functions
result
result function 1 function 2 test 1 test 2
Comments
Post a Comment