In this tutorial, we will learn about operators used in SQL.
SQL Operators is a reserved word or a character used in SQL statements to perform operations such as comparisons and arithmetic operations.
Generally, There is 3 type of operator in SQL as follow:
Let's assume two variables "a" and "b", Variable "a" hold value 100 and variable "b" hold value 50.
| Operator | Description | Example |
| + | Add - it is used to perform addition. | a+b will give 150 |
| - | Subtract - it is used to perform subtraction. | a-b will give 50 |
| * | Multiply - it used to perform multiplication. | a*b will give 5000 |
| / | Divide - it is used to perform division | a/b will give 2 |
| % | Modulus - it is used to return a remainder. | a%2 will give 0 |
Let's assume two variables "a" and "b", Variable "a" hold value 100 and variable "b" hold value 50.
| Operator | Description | Example |
| = | It is used to compare two operands are equal or not.if yes then condition becomes true. | (a=b) is not true |
| > | It is used to check that left operand is greater than right operand or not.if yes then condition becomes true. | (a > b) is true |
| < | It is used to check that left operand is less than right operand or not.if yes then condition becomes true. | (a < b) is false |
| >= | It is used to check that left operand is greater than or equal to right operand or not.if yes then condition becomes true. | (a >= b) is true |
| <= | It is used to check that left operand is less than or equal to right operand or not.if yes then condition becomes true. | (a <= b) is true |
| <> | It is used to check that left operand is not equal to right operand or not.if yes then condition becomes true. | (a<>b) is true |
| != | It is used to check that left operand is not equal to right operand or not.if yes then condition becomes true. | (a!=b) is true |
| !< | It is used to check that left operand is not less than right operand or not.if yes then condition becomes true. | (a!<b) is true |
| !> | It is used to check that left operand is not greater than right operand or not.if yes then condition becomes true. | (a !> b) is false |
| Operator | Description |
| ALL | ALL operator returns TRUE if all of the subquery values meet the condition. |
| AND | AND operator returns TRUE if all the conditions separated by AND is TRUE. |
| ANY | ANY operator returns TRUE if any of the subquery values meet the condition. |
| BETWEEN | BETWEEN operator display records if the operand is within the range of comparisons. |
| EXISTS | EXISTS operator returns TRUE if the subquery returns one or more records. |
| IN | IN operator returns TRUE if the operand is equal to one of a list of expressions. |
| LIKE | LIKE Operator returns TRUE if the operand matches a pattern using wildcard operators. |
| NOT | NOT operator displays a record if the condition(s) is NOT TRUE. |
| OR | OR operator returns TRUE if any of the conditions separated by OR is TRUE. |
| SOME | SOME operator returns TRUE if any of the subquery values meet the condition. |