Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql uses of "less than or equal to" & "not greater than"

  • <= is the less than or equal to operator.
  • !> is the not greater than operator.

Why are there two different comparison operators that seem to do the same thing.

Is there any situation where one would be prefered over the other?

like image 853
harryovers Avatar asked Nov 03 '11 17:11

harryovers


2 Answers

<= and > are comparison operators, not logical operators. ! is a logical operator (means NOT). When you combine ! and >, you're simply inverting a comparison operator, so your end result is the same.

Having said that, <= is the common form, so I'd say it's preferred, for readability if nothing else. I don't know if there's a performance benefit to either, but I doubt it.

Edit: Also, you didn't say which flavor of SQL you're dealing with. As @harryovers pointed out, that's a valid operator in MS-SQL, but it might not work everywhere.

like image 148
ddrace Avatar answered Oct 18 '22 01:10

ddrace


I can't see why you would use one over the other, but !> is not in ISO standards, and based on that I would say that <= is the preferred way.

like image 3
James Johnson Avatar answered Oct 17 '22 23:10

James Johnson