2

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

2
  • You mean, you want to select all rows where EmpCode starts with a digit? Please be a little more specific. Commented Sep 21, 2010 at 10:31
  • @fredley Sorry! pl look at my edit Commented Sep 21, 2010 at 10:34

1 Answer 1

4
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...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.