PDA

View Full Version : Seeing if MySQL field Contains Digit



Mike
12-19-2005, 02:11 PM
Hi guys,

I think this has an easy solution but I can't figure it out anyway!

I want to write a query which sees if a field contains a certain number number. The fields are made up in the format like "1 3 4 5", so I want to be able to make a query that will check if a number is in that field. Get me? :)

Could anyone help?

Thanks,
Mike

r2d2
12-19-2005, 02:44 PM
Something like this: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html ?

So you would do :
SELECT fields FROM the_table WHERE MATCH (number_field) AGAINST ('1');

I think this is what you want? The field you are searching is text right?

Remember to set the field to FULLTEXT when doing this!

That was from a quick search, I think I have used this in the past:


SELECT fields FROM the_table WHERE number_field LIKE '%1%';

Mike
12-20-2005, 09:22 AM
I tried the second version and that worked fine, cheers r2 :)