Logical Operators in SQL

# Logical Operators in SQL

clickHere
Vikram Singh
Assistant Manager - Content
Updated on Nov 22, 2022 19:37 IST

While working with a large dataset you have to perform a different kind of operation to extract or manipulate the the data from the dataset. To perform these operation we nee different types of operators. In this article we will discuss different types of Logical Operator in SQL.

In the previous article, we have discussed SQL Comparison and Arithmetic Operator. Now in this article, we will discuss different Logical Operators in SQL.

## Table of Content

Logical Operators

## Logical Operators

Logical operators are symbols or words that are used to connect two or more expressions. Some of the common logical operators are AND, OR, and NOT. SQL has more than these logical operators.

Here, is the list of Logical Operators in SQL.

Now we will use the Employee dataset (that contains Employee ID, Name, Gender, Department, Education, Month of Joining, and CTC) to do some examples to get a clear understanding of different logical operators.

### AND

Example 1: Find the details of all the employees who are working in Sales department and are undergraduates.

Query

` `
`SELECT *FROM EmployeeWHERE department = ‘Sales’ AND Education = ‘UG’;Copy code`

Output

### OR

Example 2: Find the employee detail of all the employees who joined the month of march or CTC is greater than 20 lacs.

Query

` `
`SELECT *FROM EmployeeWHERE Month of Joining = ‘March’ OR CTC > 20;Copy code`

Output

### NOT

Example 3: Find the details of all the employee who are undergraduate but not working in the HR department.

Query

` `
`SELECT *FROM EmployeeWHERE Education  = ‘UG’ AND Department NOT ‘HR’;Copy code`

Output

Must Read: Types of Keys in Database

### LIKE

Example 4: Find the detail of the employees who are working in the department that ends with ‘ing’.

Query

` `
`SELECT *FROM EmployeeWHERE Department LIKE ‘%ing’;Copy code`

Output

Must Read: Types of Keys in Database

### IN

Example 5: Find the details of the employees who are working in HR and Engineering department.

Query

` `
`SELECT *FROM EmployeeWHERE Department IN (‘Engineering’, ‘HR’);Copy code`

Output

Must Read: Aggregate and Scalar Function in SQL

### BETWEEN

Example 6: Find the employee details whose CTC is in BETWEEN 8 and 15.

Query

` `
`SELECT *FROM EmployeeWHERE CTC BETWEEN 8 AND 15;Copy code`

Must Read: Difference between SQL and NoSQL

Must Check: SQL Online Course and Certifications

### ISNULL

Example 7: Find the detail of the employees where Education is NULL.

` `
`SELECT *FROM EmployeeWHERE Education IS NULL;Copy code`

Output

## Conclusion

In this article, we have discussed different types of Logical Operators in SQL with the help of examples.