tags:

views:

45

answers:

2

Hey, first I use SQL + PHP the type of DB is MYSQL.

I have a column with the many strings, but I want to search the string 08/08/10 if it exists 5 times for example in the column, how do I do it?

** If I will do:

SELECT * FROM x WHERE y LIKE '%08/08/10%'

Maybe it exists, but I don't know if 5 times..

Thank you very much!

+3  A: 

select count(1) from x where y like '%08/08/10%' -outputs exact number of rows that have y like '%08/08/10%'

no group by needed in this particular case.

Alexander
Thank you very much! I didnt know about this function in SQL. Again - thank you!!
Luis
+2  A: 

fetch rows where the string exists at least once and use php (e.g. substr_count) to count occurrences.

foreach($db->fetchAll(" where y like '%blah%' ") as $rec)
   if(substr_count($rec->y, "blah") == 5)
       bingo...

it also may help to tell us more about your problem - maybe there are better ways to structure the database

stereofrog
I tried the solution of Alexander but its what I search of..But your answer its what I search of.. So, thank you very much!I just change the loop from foreach to while ans its working perffect.Thank you again. Luis.
Luis