28
create table mixedvalues (value varchar(50));

insert into mixedvalues values ('100');
insert into mixedvalues values ('ABC100');
insert into mixedvalues values ('200');
insert into mixedvalues values ('EFEA200');
insert into mixedvalues values ('300');
insert into mixedvalues values ('AAFASF300');
insert into mixedvalues values ('400');
insert into mixedvalues values ('AERG400');
insert into mixedvalues values ('500');
insert into mixedvalues values ('AGE500');

i want to select only non-numeric(alpha numeric) values, i.e ABC100,EFEA200,AAFASF300,AERG400,AGE500.

i have the code for selecting numeric values, i.e 100,200....

SELECT * 
FROM mixedvalues 
WHERE value REGEXP '^[0-9]+$';

Please help me,iam a beginner.

3
  • Do the letters A, B, and C always appear in each non-numeric record? Commented Oct 21, 2016 at 10:31
  • You can use LIKE keyword for this WHERE value like '%200' Commented Oct 21, 2016 at 10:31
  • @TimBiegeleisen no, it maynot be always ABC, any random alphabet Commented Oct 21, 2016 at 10:33

2 Answers 2

33

The regex [a-zA-Z] should only fire true if a value contains at least one letter.

SELECT * 
FROM mixedvalues 
WHERE value REGEXP '[a-zA-Z]';   -- or REGEXP '[[:alpha:]]'
Sign up to request clarification or add additional context in comments.

2 Comments

"non numeric" does not mean only containing letters. You also could have other chars...
@CyrilJacquart The OP mentioned i want to select only non-numeric(alpha numeric) values ... I interpret this, along with the sample data provided, that all inputs would be strictly alphanumeric.
9

The REGEXP '^[^0-9]+$' selects all non numeric characters

SELECT state
FROM `enquiry`
GROUP BY state
HAVING state REGEXP '^[^0-9]+$'

3 Comments

This did not seem to catch special characters for some reason....
This will select only the ones that have non numeric at start. Use '[^0-9]' if you want to search for non-numeric anywhere in string
I believe this is a better solution since it will work with any non numeric value, not only alphabet. Thanks

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.