sooraj s pillai
sooraj s pillai

Reputation: 916

Group_concat with if condition in mysql

I am not much familiar with mysql here i am giving a portion of my query

(SELECT GROUP_CONCAT(Q.gender_id SEPARATOR ' , ') FROM path_career_gender_compatibility Q WHERE Q.data_entry_id = '1') AS career_gender_compatibility

here i am getting result as

1 , 2 , 3 

but i want record like this

male,female,others

table structure

I dont know how to use a condition inside group_concat . I hope you all understand the problem any help is appreciable.

Upvotes: 0

Views: 1563

Answers (1)

Oto Shavadze
Oto Shavadze

Reputation: 42763

Probably you need CASE expression:

SELECT GROUP_CONCAT(case when Q.gender_id = 1 then 'male' when Q.gender_id = 2 then 'female' else 'other' end SEPARATOR ' , ') 
FROM path_career_gender_compatibility Q 
WHERE Q.data_entry_id = '1'

Upvotes: 1

Related Questions