mysql - show null records in group_concat -



mysql - show null records in group_concat -

this question has reply here:

include null results in group_concat 2 answers

i have 2 tables this

profile_answers

+---------+------------+ | id | class_name | +---------+------------+ | 1 | class 1 | | 2 | class 2 | | 3 | class 1 | +---------+------------+

educations

+---------+--------------------+------------+ | id | profile_answers_id | sample | +---------+--------------------+------------+ | 1 | 1 | 1234 | | 2 | 1 | 2334 | | 3 | 1 | 3434 | +---------+------------+--------------------+

i ran query,

select educations.profile_answer_id, group_concat(educations.sample) educations left bring together profile_answers on educations.profile_answers_id = profile_answers.id

i got

+--------+--------------------+-------------+ | id | sample | +---------+--------------------+------------+ | 1 | 1234,2334,3434 | +---------+------------+--------------------+

i want,

+--------+--------------------+-------------+ | id | sample | +---------+--------------------+------------+ | 1 | 1234,2334,3434 | | 2 | null | | 3 | null | +---------+------------+--------------------+

i tried, isnull, ifnull combination of group_by profile_answers.id gave me right result, turned out pretty expensive in terms of run time

this reply in previous question...

looks you're missing grouping by:

select profile_answers.id, group_concat(educations.sample) profile_answers left bring together educations on educations.profile_answers_id = profile_answers.id grouping profile_answers.id

i altered bring together create profile_answers table main table.

good luck.

mysql performance group-concat

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -