Operator:
An operator is a special symbol which used to perform a specific operation.
SQL operators:
SQL operators are the reserved words or special symbols or characters that are used to perform specific operations.
Types of SQL operators:
- 1. SQL Arithmetic Operators
- 2. SQL Comparison Operators
- 3. SQL Logical Operators
1. SQL Arithmetic Operators:
Let us consider the two variables a and b, where a hold 20 and b hold 40.
Operator | Description | Example |
+ | 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 operand | b / 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:
Let us consider the two variables a and b, where a hold 20 and b hold 40.
Operator | Description | Example |
= | 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
Operator | Description |
ALL | It is used to compare a value to all values in another value set. |
AND | It allows the existence of multiple conditions in an SQL statement’s WHERE clause. |
ANY | It is used to compare a value to any applicable value in the list according to the condition. |
BETWEEN | It is used to search for values that are within a set of values, given the minimum value and the maximum value. |
EXISTS | It is used to search for the presence of a row in a specified table that meets certain criteria. |
IN | The IN operator is used to compare a value to a list of literal values that have been specified. |
LIKE | It is used to compare a value to similar values using wildcard operators. |
NOT | It 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. |
OR | It is used to combine multiple conditions in an SQL statement’s WHERE clause. |
IS NULL | It is used to compare a value with a NULL value. |
UNIQUE | It searches every row of a specified table for uniqueness (no duplicates). |
No comments:
Post a Comment