Sql uses less than or equal to and no more

Why are there two different logical operators that seem to do the same thing (<= and!>), Is there a situation in which one could prefer each other?

+6
source share
6 answers

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

Having said that, <= is a general form, so I would say that it is preferable, for readability, if nothing else. I don’t know if there is a performance advantage, but I doubt it.

Edit: Also, you did not say what kind of SQL taste you mean. As @harryovers noted, a valid statement in MS-SQL, but it may not work everywhere.

+7
source

I don’t understand why you will use one of them, but !> Does not comply with ISO standards, and based on this, I would say that <= is the preferred way.

+4
source

One reason to have an alternative! > is to simplify the installation of SQL inside XML. Less than a character introduces XML tags. If SQL with <is included in XML or HTML, it must be escaped as & LT ;. A sign larger than a sign does not mean anything special unless preceded by a smaller sign.

+4
source

No, there is no difference. The only reason I can think is to make it more understandable to a person in a certain context.

eg. for the same reason, I would use < 5 , and not <= 4 , if the value 5 mattered for some restriction in context.

+1
source

!= ,! !< and !> are not standard comparison operators and are supported by only a few systems, and SQL-Server is one: msdn: Comparison operators (Transact-SQL) . MySQL also supports != , But only that, not the other two.

The equivalent standard SQL comparison operators are <> , >= and <= .

In all situations, I would prefer the standard. You don't know when you need to port your code to another platform (and have fewer errors to solve.)

+1
source

When you say logical logical logical AND and OR , I never saw! > I saw <>

If you mean != And <> , then they match.

0
source

Source: https://habr.com/ru/post/900721/


All Articles