Comparison operators are used to build a comparable condition between two expressions and returns a logical output as True or False.
Following are the comparison operators.
Operator Description Syntax Example
= (Equals) Compares two expressions. Returns true if both expressions are equal, else returns false. expression1 = expression2 SELECT ProductID FROM Product WHERE ProductID = 1
<> (Not equal to) Compares two expressions. Returns true if both expressions are not equal, else returns false. expression1 <> expression2 SELECT ProductID FROM Product WHERE ProductID <> 1
!= (Not equal to) Compares two expressions. Returns true if both expressions are not equal, else returns false. Similar in performance and result compared to <> Operator, but != is not ANSI compliant. expression1 != expression2 SELECT ProductID FROM Product WHERE ProductID != 1
> (Greater than) Compares two expressions. Returns true if left expression has value greater than the right expression. expression1 > expression2 SELECT ProductID FROM Product WHERE ProductID > 5
< (Less than) Compares two expressions. Returns true if left expression has value less than the right expression. expression1 < expression2 SELECT ProductID FROM Product WHERE ProductID < 5
!> (Not greater than) Compares two expressions. Returns true if left expression does not have value greater than the right expression. This operator is not ANSI compliant. expression1 !> expression2 SELECT ProductID FROM Product WHERE ProductID !> 5
!< (Not less than) Compares two expressions. Returns true if left expression does not have value less than the right expression. This operator is not ANSI compliant. expression1 !< expression2 SELECT ProductID FROM Product WHERE ProductID !< 5
>= (Greater than or equal to) Compares two expressions. Returns true if left expression has value greater than or equal to the right expression. expression1 >= expression2 SELECT ProductID FROM Product WHERE ProductID >= 5
<= (Less than or equal to) Compares two expressions. Returns true if left expression has value less than or equal to the right expression. expression1 <= expression2 SELECT ProductID FROM Product WHERE ProductID <= 5