• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

mySQL compare string as numeric

I'm querying a database I don't have control over. There is a string field which holds numbers, NULL and ''. What do I need to do to compare the string field as a number

Ex. I have the following values in the table
NULL
''
'0'
'1'
'2'
'11'

I want to select * from table where field < 2

It should only return 1 and 0 (I would also be OK with it treating NULL and '' as 0 and returning those), not the 11 or 2.
0
Darksbane
Asked:
Darksbane
  • 2
1 Solution
 
DalHorinekCommented:
Try select * from table where CAST(field, INT) < 2
0
 
DalHorinekCommented:
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now