Monday, February 4, 2013

Check if a string contains numbers by Mysql

how do I check if a string in a MySQL field contains a number then delete them?
 
tbl_tags
 -------------
| id | tag    |
 -------------
| 1  | hello  |
| 2  | hello2 |
| 3  | 2hello |
| 4  | hel3lo |
                   -------------

The only way I can think of is to do each number individually and use LIKE '%1%' OR LIKE '%2%' etc. But there must be an easier way?

Check out the MySQL Regex methods. Something like the following should work.
SELECT * FROM table WHERE tag REGEXP '[0-9]'


No comments:

Post a Comment

Thanks....