Monday, January 28, 2013

How to search multiple values(IDs) in a MySQL field using regular expression?

I have a database field with the IDs like "~1~2~3~4~5~6~7~8~9~10~11". I want to list all the records having 6 and 11 available in the field with a single query.



MySQL Query:

SELECT interests 
FROM personal 
WHERE interests != '' 
AND interests REGEXP "^[0-9~]+6[0-9~]+11[0-9~]*$"