Jump to content

[SOLVED] Help with like query


Darkmatter5

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/140215-solved-help-with-like-query/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.