Home > Database > Mysql Tutorial > body text

Why Doesn\'t My MySQL Query Find My Float Value?

Mary-Kate Olsen
Release: 2024-10-31 18:30:29
Original
668 people have browsed it

 Why Doesn't My MySQL Query Find My Float Value?

Troubleshooting MySQL FLOAT Selection Issue

When attempting to retrieve a row from a MySQL table based on a float value, a common issue arises when the matching value returns zero rows. This problem can manifest when the floats in the table and the query have different precision.

For instance, consider the following query:

SELECT * FROM `table` WHERE `ident`='ident23' AND `price`='101.31';
Copy after login

Even though the table contains a row with ident='ident23' and price='101.31', the query might not match it due to different precision. To address this, you can cast the price column to a DECIMAL type:

SELECT * FROM table WHERE CAST(price AS DECIMAL) = CAST(101.31 AS DECIMAL);
Copy after login

This will ensure that both values are compared with the same precision, allowing the query to retrieve the correct row.

Alternatively, you can consider altering the price column to a DECIMAL type permanently. DECIMAL is generally the preferred data type for handling monetary values due to its higher precision compared to FLOAT.

The above is the detailed content of Why Doesn\'t My MySQL Query Find My Float Value?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template