Logical Operators

In this post , we will discuss about Logical Operators.

AND Operator :

AND Operator is used to filter the records based on two or more than two conditions.

It is specified in the WHERE clause.

It filters the records only if all the specified conditions are true.

Syntax:

The record is selected if all the conditions specified in WHERE Clause are satisfied.

SELECT  <Col Name> FROM <Tablename>

WHERE <Condition 1> AND <Condition 2>…………AND <Condition N>;

OR Operator :

OR Operator is used to filter the records based on two or more than two conditions.

It is specified in the WHERE clause.

It filters the records only if either of the specified condition is true.

Syntax :

The record is selected if any of the condition specified in WHERE Clause is satisfied.

SELECT  <Col Name> FROM <Tablename>

WHERE <Condition 1> OR <Condition 2>…………OR <Condition N>;

Note : AND and OR operators can be used in combination as well.

SELECT  <Col Name> FROM <Tablename>

WHERE <Condition 1> AND <Condition 2> OR  <Condition 3>;

NOT Operator :

NOT Operator returns the record if the condition specified is not true.

It is specified in the WHERE clause.

It is a negate operator .

It can be used with other operators and just reverses the operator action like NOT IN , NOT BETWEEN, NOT EXISTS.

Syntax :

The record is selected if any of the condition specified in WHERE Clause is satisfied.

SELECT  <Col Name> FROM <Tablename>

WHERE  NOT( <Condition 1> );

Shikha Katariya

Shikha

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *