Solved

mySQL compare string as numeric

Posted on 2010-11-15
2
424 Views
Last Modified: 2012-05-10
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
Comment
Question by:Darksbane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 6

Expert Comment

by:DalHorinek
ID: 34139122
Try select * from table where CAST(field, INT) < 2
0
 
LVL 6

Accepted Solution

by:
DalHorinek earned 500 total points
ID: 34139137
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question