Harry
Harry

Reputation: 1699

MySQL Query - comparing string with set type

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?

Upvotes: 3

Views: 964

Answers (1)

juergen d
juergen d

Reputation: 204756

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

FIND_IN_SET Doc

Upvotes: 7

Related Questions