Wednesday 27 July 2011

SQL Operators


An operator is a symbol specifying an action that is performed on one or more expressions. 

Types of Operators:

·         Arithmetic Operators

·         Logical Operators

·         Comparison Operators

 

Arithmetic Operators: Arithmetic operators perform mathematical operations on two expressions of one or more of the data types of the numeric data type category.

There are following operators;

Operator

Meaning

+ (ADD)

Addition ie, select (2+3) gives 5

- (Subtract)

Subtraction ie, select (5 - 3) gives 2

* (Multiply)

Multiplication ie, select (2*3) gives 6

/ (Divide)

Division ie, select (8/3) gives 2

% (Modulo)

Returns the integer remainder of a division. For example, 12 % 5 = 2 because the remainder of 12 divided by 5 is 2. select (9%3)gives 0



Logical Operators: Logical operators test for the truth of some condition. Logical operators, like comparison operators, return a Boolean data type with a value of TRUE, FALSE, or UNKNOWN.

There are following operators;

Operator

Meaning

ALL

TRUE if all of a set of comparisons are TRUE.

AND

TRUE if both Boolean expressions are TRUE.

ANY

TRUE if any one of a set of comparisons are TRUE.

BETWEEN

TRUE if the operand is within a range.

EXISTS

TRUE if a subquery contains any rows.

IN

TRUE if the operand is equal to one of a list of expressions.

LIKE

TRUE if the operand matches a pattern.

NOT

Reverses the value of any other Boolean operator.

OR

TRUE if either Boolean expression is TRUE.

SOME                       

TRUE if some of a set of comparisons are TRUE.



Comparison Operators:

Comparison operators are used to compare the column data with specific values in a condition.
Comparison Operators are also used along with the SELECT statement to filter data based on specific conditions.
The below table describes each comparison operator.
Operator
Meaning
= (Equals)
Equal to
> (Greater Than)
Greater than
< (Less Than)
Less than
>= (Greater Than or Equal To)
Greater than or equal to
<= (Less Than or Equal To)
Less than or equal to
<> (Not Equal To)
Not equal to
!= (Not Equal To)
Not equal to
!< (Not Less Than)
Not less than
!> (Not Greater Than)
Not greater than

No comments:

Post a Comment