Select query with regular expression - MySql
I want to select records if a particular column has numbers in its name.
Table 1
ID EmpCode EmpName
1 1C Name1
2 2C 开发者_高级运维 Name2
3 C3 Name3
4 CD Name4
5 CD Name4
6 C6D Name6
7 7CD Name7
I need to select records 1,2,3,6,7 based on EmpCode. How can this be performed?
EDIT: EmpCode can have number in any position
SELECT * FROM table WHERE EmpCode REGEXP '[0-9]'
Or alternatively, if you want to check for 'starts with a digit' instead of 'contains a digit':
SELECT * FROM table WHERE EmpCode REGEXP '^[0-9]'
Edit: REGEXP (not REGEX) is the correct function name...
精彩评论