Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Query - comparing string with set type

Tags:

php

mysql

set

I have a column in my table of type SET('alpha','beta','gamma','delta','...','omega') and name 'alphabet'

My PHP query is

$string = "gamma"

SELECT * FROM table WHERE alphabet LIKE "%$string%"

So I would like to return all of the rows where gamma is in the column alphabet, regardless of whar other values are in there too as it is a SET type.

What would the sql query be?

like image 236
Harry Avatar asked Jul 17 '26 15:07

Harry


1 Answers

SELECT * FROM table WHERE find_in_set('$string', alphabet) > 0

FIND_IN_SET Doc

like image 160
juergen d Avatar answered Jul 20 '26 04:07

juergen d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!