Wednesday, February 4, 2015

SQL Operators


SQL Operators


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:
  1. SQL Arithmetic Operators
  2. SQL Comparison Operators
  3. SQL Logical Operators

SQL Arithmetic Operators:

Let's assume two variables "a" and "b". Here "a" is valued 50 and "b" valued 100.
Example:
OperatorsDescriptionsExamples
+It is used to add containing values of both operandsa+b will give 150
-It subtracts right hand operand from left hand operanda-b will give -50
*It multiply both operand?s valuesa*b will give 5000
/It divides left hand operand by right hand operandb/a will give 2
%It divides left hand operand by right hand operand and returns reminderb%a will give 0

SQL Comparison Operators:

Let's take two variables "a" and "b" that are valued 50 and 100.
OperatorDescriptionExample
=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.
OperatorDescription
ALLthis is used to compare a value to all values in another value set.
ANDthis operator allows the existence of multiple conditions in an SQL statement.
ANYthis operator is used to compare the value in list according to the condition.
BETWEENthis operator is used to search for values, that are within a set of values
INthis operator is used to compare a value to that specified list value
NOTthe NOT operator reverse the meaning of any logical operator
ORthis operator is used to combine multiple conditions in SQL statements
EXISTSthe EXISTS operator is used to search for the presence of a row in a specified table
LIKEthis operator is used to compare a value to similar values using wildcard operator

No comments:

Post a Comment