ankit ankit - 6 months ago 13
MySQL Question

Find number of count of a word in column in each row in mysql

I have a table name 'answer' and where answer saved given by a user for a question.
User give multiple answer of a question.So answer save as string in 'answer' column.
My table look like this

id userid questionid answer

1 2 5 red,blue,white,green

2 3 5 red,blue

3 5 5 red,white

4 6 5 blue,white,green

5 7 5 red,blue,white,green

I want to select those userid whose answer 3 value(blue,white,green) or more than 3(red,blue,white,green).
I have tried with
function but it not work.
Please help me.


Based on the link i provided on my comment ealier, you can accomplish what you want by doing this:

SELECT userid    
FROM AnswersTable 
         (LENGTH(answer) - LENGTH( REPLACE ( answer, ",", "") ) ) / LENGTH(",")        
       ) > 2