Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL select using wildcard (but wildcard in field)

I have a mysql 5 table with a char field holding

DOG
DOUG
CAT
MOUSE

Now I want to SELECT on this field, finding any rows where that field exist within a string, like "DOGGY". (This is opposite of how you normally use a wildcard). So I want a select something like: SELECT FROM TABLE WHERE FIELD IS SUBSTRING OF "DOGGY"

Is this possible?

like image 822
Michelle Dupuis Avatar asked Mar 04 '12 03:03

Michelle Dupuis


2 Answers

select * from mytable where 'doggy' like concat('%',mycol,'%')
like image 67
gordy Avatar answered Oct 24 '22 21:10

gordy


You should be able to use LOCATE() to achieve this:

SELECT * FROM MyTable WHERE LOCATE(MyField, 'DOGGY') != 0;
like image 44
Paul Bellora Avatar answered Oct 24 '22 20:10

Paul Bellora