开发者

SQL comparison operators

are these two statements the same?

query 1: WHERE salary > 999;

query 2: WHERE salary >= 1000;

I thought they were, but apparently according to my peers they are n开发者_运维知识库ot (Though they have failed to explain why).


That's not necessarily the same. If you're storing doubles, when you do:

WHERE salary >= 1000;

you're not taking in count all values that are between 999 and 1000 (eg. 999.50)

Otherwise, if you're working with integers, that's true, not only in programming, but also in maths.

n > k <=> n >= k+1


The two queries will give the same results, if salary is an integral type. But if salary is some real type, then the results will be different.


This is entirely dependant on the datatype of salary.

If salary is an INT or a BIGINT then yes they will yield the same results.

If salary is pretty much any other datatype, the first once will return results for 999.9, but the second one won't.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜