value->{1,2,Yes,No,5,6}
select if((value is numeric),value,'not a numeric') as column_name
how to implement this if in my mysql select query
value->{1,2,Yes,No,5,6}
select if((value is numeric),value,'not a numeric') as column_name
how to implement this if in my mysql select query
This should do it :)
select if(field REGEXP '^-?[0-9]+$' > 0, field, 'not a numeric') as column_name
Example:
SELECT '12345' REGEXP '^-?[0-9]+$'
Returns: 1 (its a number)
SELECT 'abcdef' REGEXP '^-?[0-9]+$'
Returns: 0 (its NOT a number)
This is an old question, but when I needed the same thing the fastest solution was
select if((value *1),value, 'not a number') as column_name;
Granted, this will not consider zero a number, but neither did the Romans and they did ok for thousands of years. For me, given the improved speed across the hundreds of millions of rows, this was the best solution.
You can try it-
SELECT IF(table_column*1>0,table_column,'Not a Numeric')
FROM your_table;
Note: If there is a value "9 hello" then it will be treat as numeric as 9 is numeric value, if you need to exclude it also then revert. But in your question there is no such value.