SQL AND Operator

AND Operator is used to applying multiple conditions in the query. AND Operator is a part of the logical operator and It is applicable in INSERT/UPDATE/DELETE operations.

In SELECT Statement

Syntax:-


SELECT column(s) 
FROM table_name 
WHERE condition1 AND condition2 AND condition3....

In UPDATE Statement

Syntax:-


UPDATE table_name
SET column1=value1, column2=value2.....
WHERE condition1 AND condition2 AND condition3....

In INSERT Statement

Syntax:-


INSERT INTO table_name (column1,column2.....) 
VALUES (value1,value2....)
WHERE condition1 AND condition2 AND condition3....

Example:- Suppose we have employees table which has 7 records


+----+------------+-----------+----------------+-----------+
| id | first_name | last_name | email          | country   |
+----+------------+-----------+----------------+-----------+
|  1 | John       | Tailor    | john@abc.com   | USA       |
|  2 | Rom        | Tailor    | rom@abc.com    | USA       |
|  3 | Andrew     | Symonds   | andrew@abc.com | Australia |
|  4 | Miacle     | clerk     | miacle@abc.com | Australia |
|  5 | Sachin     | Tendulkar | sachin@abc.com | India     |
|  6 | Virat      | Kohli     | virat@abc.com  | India     |
|  7 | rohit      | NULL      | rohit@abc.com  | India     |

Now, we have to get the employees who have country INDIA and firstName Virat.


SELECT * FROM employees
where country='India' AND first_name='Virat';

Output:-


 +----+------------+-----------+---------------+---------+
| id | first_name | last_name | email         | country |
+----+------------+-----------+---------------+---------+
|  6 | Virat      | Kohli     | virat@abc.com | India   |
+----+------------+-----------+---------------+---------+
1 row in set (0.00 sec)

SQL AND Operator – Interview Questions

Q 1: What does the AND operator do?
Ans: AND returns true when all conditions are true.
Q 2: Can AND be used in WHERE clause?
Ans: Yes, it combines multiple conditions.
Q 3: How many conditions can AND combine?
Ans: Any number of conditions.
Q 4: Does AND have higher priority than OR?
Ans: Yes, AND is evaluated before OR.
Q 5: Does AND affect performance?
Ans: Complex conditions may impact performance.

SQL AND Operator – Objective Questions (MCQs)

Q1. What does the AND operator do in SQL?






Q2. AND operator is mostly used with which clause?






Q3. Which query uses AND correctly?






Q4. AND operator returns TRUE when:






Q5. AND operator is evaluated with which type of logic?






Related SQL AND Operator Topics