What are Logical operators in SQL ? | Logical Operators Example

Logical operators in SQL :

In previous article i have explained the Functions in SQL with real life examples.The another important topic while learning SQL is Operators in SQL.Operators are nothing but the the statement which are used to perform SQL Operations.SQL Operators are mostly used in Where clause of SQL statement.Operators are basically used to specify the conditions to SQL Statement.In this article i will explain about the Logical operators in SQL.These operators compare two conditions at a time to determine whether a row can be selected for the output.Logical Operators in SQL are used to compare the one or more expressions and give the result. This article will give you the detailed description about the Logical operators in SQL with real life examples.

“Operators are nothing but the the statement which are used to perform SQL Operations”

There are following different types of Operators in SQL:

1. Arithmetic Operators

2.Logical Operators

3.Comparison Operators

4.Negation Operators

2.Logical Operators in SQL:

Logical Operators are used to perform the logical operations between two variables.What are different logical operations in SQL? There are following logical operators in SQL.This section will give you examples of Logical Operators in SQL.I will try to give all the real life examples of Logical Operators in SQL.

1.AND Operator:

AND operator is used to give the multiple conditions at a same time to SQL Statement.The And operator is used in where clause of SQL statement.

Example:

Select * from Employee where name=’Divya’ and ‘Yodhini’;

It will display all the records from Employee table where name is Divya and Yodhini.

2.OR Operator:

OR Operator is used to combine multiple conditions in the database.It simply means whether this or this.

Example:

Select * from Employee where name=’Divya’ OR ‘Yodhini’;

It will display all the records from Employee table where name is Divya OR Yodhini.

3.IN Operator:

IN Operator is used to fetch the 2 or more specific records from the database.

Example:

Select * from Employee where name IN (‘Divya’,’Yodhini’);

It will display specific records for the employees where name is Divya and Yodhini.

4.ALL Operator:

ALL Operator is used to compare all the values from another dataset and fetch the specific records from the table.

Example:

Select * from Student where 10000 >ALL (Select Fees from Student_Fees);

The above statement will display all the records from Student table where Student fees is > 10000 which we are fetching from different table named ‘Student_Fees’

5.Any Operator:

Any Operator is used to compare the values from Any value from another table with that condition.

Example:

Select * from Student where 10000 >ANY (Select Fees from Student_Fees);

The above statement will display ANY of the records from Student table where Student fees is > 10000 which we are fetching from different table named ‘Student_Fees’

6.Between..And Operator:

Between..And Operator is used to fetch the records from the table where values between first_value (minimum value) and second value(maximum value).

Example:

Select * from Student where fees between 1000 and 2000;

The above statement will fetch all the Students information from student table where Fees is greater than 1000 and less than 2000.

7.LIKE Operator:

Like Operator is most used operator which is used to compare the values from the table using wildcard operators like ‘%’ ‘_’ etc.

Example:

select * from Student where name like ‘Ami%’;

All student information will be displayed where name starts with Ami.

select * from Student where name like ‘A_ _ _’;

All Students information will be displayed where name starts with A which has length 4.

8.Exist Operator:

Exist Operator is used to specify the presence of specific row which has some specific condition.

Select * from Student where name Exist(‘Amit’);

The above statement will display the records where name Existing Amit.

Hope this article will helpful for programmers.If you like this article or if you have any suggestions for this article kindly comment in comment section below.

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Recent Posts

What is Root Cause Analysis (RCA) With real examples

In my previous article I have given details about application support engineer day to day…

4 weeks ago

Application Support Engineer Day to day responsibilities

In my previous articles I have given the roles and responsibilities of L1,L2 and L3…

1 month ago

What is mean by SLA ( Service Level Agreement) with Examples?

In my previous articles i have given the hierarchy of production support in real company…

1 month ago

What is Production support Hierarchy in organization?

In this article i would like to provide information about production support organization structure or…

1 month ago

What are roles and responsibilities for L3 Support Engineer?

In my previous article I have given roles for L1 and L2 support engineer with…

1 month ago

What are roles and responsibilities of L2 Engineer?

I have started this new series of how to become application support engineer. This article…

1 month ago