medk medk - 29 days ago 7
SQL Question

mySQLi Select number when contains white space

How to select from table where price is >= 3000 when the field type is string and the numbers are formatted as: 3 000, 20 000, 5 000...

'SELECT * FROM products WHERE price >= 3000'


Is there a way to format it on the fly to remove the space and keep the results output as the original?

Answer
SELECT * FROM `products` WHERE REPLACE(price, ' ', '') > 5000

But you should really change the type of your column.

Comments