MySQL select using multiple "like"

  • Published by steve on 28 December 2011.

Scenario

Version: MySQL 5.0
Database Name: testdb
Table Name: domains
Field Name: domainame

Find all domain names that contain any digit 0 to 9.

SELECT *
FROM `domains`
WHERE `domainame` LIKE '%0%'
OR `domainame` LIKE '%1%'
OR `domainame` LIKE '%2%'
OR `domainame` LIKE '%3%'
OR `domainame` LIKE '%4%'
OR `domainame` LIKE '%5%'
OR `domainame` LIKE '%6%'
OR `domainame` LIKE '%7%'
OR `domainame` LIKE '%8%'
OR `domainame` LIKE '%9%'
OR `domainame` LIKE '%-%'