Irfan
Irfan

Reputation: 7059

Filter integer result from Mysql query

I have a Mysql query. I want to filter only integer result. My query is-

SELECT * FROM table as p WHERE p.test between 0 AND 999

But result comes this-

747
748
749
FO4001
FO4002
750
751

I want to ask two things-

1)Is there any way to exclude below result-

FO4001
FO4002

2)Why are these coming in the result?

Upvotes: 2

Views: 1627

Answers (1)

John Woo
John Woo

Reputation: 263733

Try this one, use REGEXP to test if the value is all numeric.

SELECT * 
FROM table1 
WHERE x BETWEEN 0 AND 999
      AND x REGEXP '^[0-9]+$';

SQLFiddle Demo

Upvotes: 5

Related Questions