I'm leaving this here, even though I realize that it doesn't solve the problem. It would pick up 'FEED'
. The idea might help someone else.
You can do this using rlike
or regex
:
select *
from table t
where col rlike concat('[', 'DEF', ']+')
This is constructing the simple regular expression '[DEF]+'
, which is the pattern you seem to want.
EDIT:
If you break up the original string into characters, you can do it as:
select t.col
from table t left outer join
(select 'D' as c union all select 'E' union all select 'F'
) c
on t.col like concat('%', c.c, '%')
group by t.col
having sum(c.c is null) = 0 and
sum(length(t.col) - length(replace(t.col, c.c, '')) > 1);
The first condition in the having
clause checks that all the characters are there. The second that none appear more than once. Note that this will not work if there are duplicate letters for the comparison.