Welcome Guest, Not a member yet? Register   Sign In
MySQL floats require LIKE?
#1

[eluser]slowgary[/eluser]
Maybe I'm doing something stupid but I've never seen this before. I'm trying to select a row based on a field that is a float. For some reason, I cannot do this with '=', it only works with 'LIKE'. Example:
Code:
SELECT * FROM `table` WHERE `field` = 5.5
//this returns 0 rows

SELECT * FROM `table` WHERE `field` LIKE 5.5
//this returns 1 row

Why is that? I don't like using LIKE. Thanks.
#2

[eluser]Dam1an[/eluser]
apparently it will work if you use a numeric data type instead of float. It's to do with the fact that floats themselves aren't accurate or something
#3

[eluser]slowgary[/eluser]
Well that's just silly. But it works! Thanks!
#4

[eluser]slowgary[/eluser]
Something I noticed in phpMyAdmin... when you browse a table - fields that are FLOAT are right-aligned, while fields that are DECIMAL are left-aligned. Just an observation.
#5

[eluser]Dam1an[/eluser]
[quote author="slowgary" date="1247954370"]Well that's just silly. But it works! Thanks![/quote]

Of course it's silly, you can't expect logical things to work Wink
And It's not my fault if using numeric breaks something else either lol




Theme © iAndrew 2016 - Forum software by © MyBB