Pages

Tuesday 19 May 2015

Operators in SQL

Comparison Condition Operators:


      These operators are used to compare values. The table below shows the comparison conditions operators used in SQL.


Comparison Condition Operators
Description
=
Equal to
<> 
Not equal to
> 
Greater than
>=
Greater than or equal to
< 
Less than
<=
Less than or equal to
Special Comparison Condition Operators
Description
BETWEEN…AND…
Inclusive between two values
IN(set)
Match any of the values in set
LIKE
Match a character pattern
IS NULL
Check NULL value true or false


Check out a simple example query for Comparison Operators.


SELECT first_name, department_id, salary
FROM employees
WHERE salary>=5000;
 

Output of above query:




Logical Operators:

    These opeators are used for logical comparison of values. The table below shows the logical operators used in SQL.


Logical Operators
Description
AND
Returns true if all the conditions are true
OR
Returns true if either of the conditions are true
NOT
Returns true if condition is false or vice versa

Arithmetic Operators:


Arithmetic Operators
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus

Rules of Precedence:


Evaluation Order of Operators
Operator Name
1
Arithmetic
2
Concatenation { || }
3
Comparison
4
Special Comparison Condition
5
Logical Condition


In the next post I will illustrate all the operators once again with example queries. Stayed tuned to my blog by hitting the facebook LIKE button or subscribe free to blog.