SQL operators

Operator:

A special symbol called an operator is used to perform a specific operation.

SQL operators:

The reserved words, special symbols, or characters that are used to perform specific operations in SQL are known as SQL operators.

Types of SQL operators:

  1. SQL Arithmetic Operators
  2. SQL Comparison Operators
  3. SQL Logical Operators

1. SQL Arithmetic Operators:

Consider the two variables a and b, where a holds 20 and b holds 40.

OperatorDescriptionExample
+It is used to add the operands values.a + b will give 60
It is used to subtract right hand operand from left hand operand.a – b will give -20
*It is used to multiply the operands values.a * b will give 800
/It is used to divide left hand operand by right hand operandb / a will give 2
%It is used to modulo divide left hand operand by right hand operand.b % a will give 0

2.   SQL Comparison Operators:

Consider the two variables a and b, where a holds 20 and b holds 40.

OperatorDescriptionExample
=It is used to check that the values of two operands are equal or not, if yes then condition becomes true.(a = b) is not true.
!=It is used to check that the values of two operands are equal or not, if values are not equal then condition becomes true.(a != b) is true.
<>It is used to check that the values of two operands are equal or not, if values are not equal then condition becomes true.(a <> b) is true.
>It is used to check that the value of left operand is greater than the value of right operand, if yes then condition becomes true.(a > b) is not true.
<It is used to check that the value of left operand is less than the value of right operand, if yes then condition becomes true.(a < b) is true.
>=It is used to check that the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.(a >= b) is not true.
<=It is used to check that the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.(a <= b) is true.
!<It is used to check that the value of left operand is not less than the value of right operand, if yes then condition becomes true.(a !< b) is false.
!>It is used to check that the value of left operand is not greater than the value of right operand, if yes then condition becomes true.(a !> b) is true.

3.   SQL Logical Operators

OperatorDescription
ALLIt is used to compare a value to all values in another value set.
ANDIt allows the existence of multiple conditions in an SQL statement’s WHERE clause.
ANYIt is used to compare a value to any applicable value in the list according to the condition.
BETWEENIt is used to search for values that are within a set of values, given the minimum value and the maximum value.
EXISTSIt is used to search for the presence of a row in a specified table that meets certain criteria.
INThe IN operator is used to compare a value to a list of literal values that have been specified.
LIKEIt is used to compare a value to similar values using wildcard operators.
NOTIt reverses the meaning of the logical operator with which it is used. Eg: NOT EXISTS, NOT BETWEEN, NOT IN, etc. This is a negate operator.
ORIt is used to combine multiple conditions in an SQL statement’s WHERE clause.
IS NULLIt is used to compare a value with a NULL value.
UNIQUEIt searches every row of a specified table for uniqueness (no duplicates).