469,148 Members | 1,333 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,148 developers. It's quick & easy.

Weed out alphanumeric records.

I have a varchar field in a table of about 48000 records. The vast majority
of the values are strictly numeric, but some have a letter A-Z either
prepended or appended to them. I need a query to grab all records that are
numeric.

I know I can

SELECT *
FROM my_table
WHERE
col1 NOT LIKE '%A%' AND
col1 NOT LIKE '%B%' AND
....
col1 NOT LIKE '%z%';
There has to be a cleaner/easier way?

JM
Jul 19 '05 #1
2 4727
Jim Moseby wrote:
I have a varchar field in a table of about 48000 records. The vast majority
of the values are strictly numeric, but some have a letter A-Z either
prepended or appended to them. I need a query to grab all records that are
numeric.

I know I can

SELECT *
FROM my_table
WHERE
col1 NOT LIKE '%A%' AND
col1 NOT LIKE '%B%' AND
....
col1 NOT LIKE '%z%';
There has to be a cleaner/easier way?

JM


You might use REGEXP. See http://www.mysql.com/doc/en/Regexp.html

SELECT * FROM mytable WHERE coll REGEXP "[[:digit:]]+";

Jul 19 '05 #2
Jim Moseby wrote:
I have a varchar field in a table of about 48000 records. The vast majority
of the values are strictly numeric, but some have a letter A-Z either
prepended or appended to them. I need a query to grab all records that are
numeric.

I know I can

SELECT *
FROM my_table
WHERE
col1 NOT LIKE '%A%' AND
col1 NOT LIKE '%B%' AND
....
col1 NOT LIKE '%z%';
There has to be a cleaner/easier way?

JM


You might use REGEXP. See http://www.mysql.com/doc/en/Regexp.html

SELECT * FROM mytable WHERE coll REGEXP "[[:digit:]]+";

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Daniel Tonks | last post: by
4 posts views Thread by Matt | last post: by
10 posts views Thread by Bob | last post: by
6 posts views Thread by ironcito | last post: by
7 posts views Thread by Fernando Rodríguez | last post: by
1 post views Thread by White Spirit | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.