Search code examples
sqlcomparison-operators

SQL uses of "less than or equal to" <= vs. "not greater than" !> operators


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?


Solution

  • <= 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.