SQL statements generally contain some reserved words or characters that are used to perform operations such as comparison and arithmetical operations etc. These reserved words or characters are known as operators.
Generally there are three types of operators in SQL:
- SQL Arithmetic Operators
- SQL Comparison Operators
- SQL Logical Operators
SQL Arithmetic Operators:
Let's assume two variables "a" and "b". Here "a" is valued 50 and "b" valued 100.
Example:
Operators | Descriptions | Examples |
---|---|---|
+ | It is used to add containing values of both operands | a+b will give 150 |
- | It subtracts right hand operand from left hand operand | a-b will give -50 |
* | It multiply both operand?s values | a*b will give 5000 |
/ | It divides left hand operand by right hand operand | b/a will give 2 |
% | It divides left hand operand by right hand operand and returns reminder | b%a will give 0 |
SQL Comparison Operators:
Let's take two variables "a" and "b" that are valued 50 and 100.
Operator | Description | Example |
---|---|---|
= | Examine both operands value that are equal or not,if yes condition become true. | (a=b) is not true |
!= | This is used to check the value of both operands equal or not,if not condition become true. | (a!=b) is true |
< > | Examines the operand?s value equal or not, if values are not equal condition is true | (a<>b) is true |
> | Examine the left operand value is greater than right Operand, if yes condition becomes true | (a>b) is not true |
< | Examines the left operand value is less than right Operand, if yes condition becomes true | (a |
>= | Examines that the value of left operand is greater than or equal to the value of right operand or not,if yes condition become true | (a>=b) is not true |
<= | Examines that the value of left operand is less than or equal to the value of right operand or not, if yes condition becomes true | (a<=b) is true |
!< | Examines that the left operand value is not less than the right operand value | (a! |
!> | Examines that the value of left operand is not greater than the value of right operand | (a!>b) is true |
SQL Logical Operators:
This is the list of logical operators used in SQL.
Operator | Description |
---|---|
ALL | this is used to compare a value to all values in another value set. |
AND | this operator allows the existence of multiple conditions in an SQL statement. |
ANY | this operator is used to compare the value in list according to the condition. |
BETWEEN | this operator is used to search for values, that are within a set of values |
IN | this operator is used to compare a value to that specified list value |
NOT | the NOT operator reverse the meaning of any logical operator |
OR | this operator is used to combine multiple conditions in SQL statements |
EXISTS | the EXISTS operator is used to search for the presence of a row in a specified table |
LIKE | this operator is used to compare a value to similar values using wildcard operator |
No comments:
Post a Comment