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.

Logical operators in SQL

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.

About admin 133 Articles
Oracle Consultant with Vast Experience in Oracle BI and SQL PLSQL Development

Be the first to comment

Leave a Reply

Your email address will not be published.


*