Darkmatter5 Posted January 9, 2009 Share Posted January 9, 2009 Image a table has the following records Fruits idnamecolors 1apples1,2 2oranges3 Colors idname 1red 2green 3orange Can I write a query to count how many records have a 2 in the colors field in the Fruits table? I though "SELECT COUNT(name) AS amount FROM fruits WHERE colors LIKE '%2%'" would do it, but I don't think LIKE likes numbers. Quote Link to comment https://forums.phpfreaks.com/topic/140215-solved-help-with-like-query/ Share on other sites More sharing options...
xtopolis Posted January 10, 2009 Share Posted January 10, 2009 CSV data doesn't belong in mysql row columns. You should reorganize your tables just like corbin said in the other thread. There are string searching functions (http://dev.mysql.com/doc/refman/5.0/en/string-functions.html) but I'm not going to give you an example because they are more trouble than it's worth for this example. If you had the tables setup like suggested before, you could count how many instances of 2 existed and it would tell you happily. Quote Link to comment https://forums.phpfreaks.com/topic/140215-solved-help-with-like-query/#findComment-733793 Share on other sites More sharing options...
corbin Posted January 10, 2009 Share Posted January 10, 2009 I thought this setup looked oddly familiar.... lol Quote Link to comment https://forums.phpfreaks.com/topic/140215-solved-help-with-like-query/#findComment-733827 Share on other sites More sharing options...
Darkmatter5 Posted January 12, 2009 Author Share Posted January 12, 2009 Okay okay, I get it now!! I never understood what normalizing meant. It's just splitting up data into separate databases. I got it and it's working now, thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/140215-solved-help-with-like-query/#findComment-735277 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.