Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL statement select where a column is NOT a number

Tags:

sql

php

mysql

I have a problematic script that ran, so i need to select all rows that contain values that is not a straight up integer. How do I do this? ISSTRING was on a Google search but I get an error from it saying ISSTRING does not exist. :(

So far I've muddled with:

SELECT id, area, city FROM `homes` WHERE ISSTRING(`area`) OR ISSTRING(`city`)

With no luck whatsoever...

like image 272
jeffkee Avatar asked May 01 '12 22:05

jeffkee


People also ask

How do I check if a column is numeric in MySQL?

Syntax to check if the value is an integer. select yourColumnName from yourTableName where yourColumnName REGEXP '^-?[0-9]+$'; The query wherein we have used regular expression. This will output only the integer value.

What does != Mean in MySQL?

The symbol <> in MySQL is same as not equal to operator (!=). Both gives the result in boolean or tinyint(1). If the condition becomes true, then the result will be 1 otherwise 0. Case 1 − Using != operator.

How do I exclude something in MySQL?

To check records which are NULL, use IS NULL. However, to exclude any of the records, use the NOT IN clause. Use both of them in the same query.

How do I find column numbers in MySQL?

To find the number of columns in a MySQL table, use the count(*) function with information_schema. columns and the WHERE clause.


1 Answers

RegExp works, but what I would do is check to see if abs() is equal to zero AND the field is not zero. I think this will be faster than RegExp.

SELECT id, area, city FROM `homes` WHERE (abs(area) = 0 AND area != '0') OR (abs(city) = 0 AND city != '0')
like image 162
Reza S Avatar answered Sep 29 '22 01:09

Reza S