SQL string matching

mysql, pattern-matching, sql

Solution

use `LIKE` with `%`-wildcard between the single characters:

SELECT * FROM table WHERE column LIKE '%M%F%';

note that this will only work if the characters are in correct order - searching for `FM` instead of `MF` won't give you any result. you'll also need to find a way to insert the `%`s to your search-term, but taht shouldn't be a big problem (sadly you havn't said wich programming-language you're using).

if the characters can be in random order, you'll have to built a query like:

SELECT * FROM table WHERE
  column LIKE '%M%'
AND
  column LIKE '%F%'
[more ANDs per character];

Problem

I use a string for store the days of the week, something like this: MTWTFSS. And if I search for MF (Monday and Friday) then the query must return all the strings that contain MF (for example: MWF, MTWTFS, MF, and so on). I don't know how to do this in SQL (MySQL).

Original source