SQL Where Clause

WHERE Clause is used to filter the record from the table through condition.

Syntax:-


SELECT column(s)
From table_name
WHERE [condition]

Example:- Suppose you 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 you want to get the record, which country belongs to India


SELECT * FROM employees WHERE country='India'

Output:-



+----+------------+-----------+----------------+---------+
| id | first_name | last_name | email          | country |
+----+------------+-----------+----------------+---------+
|  5 | Sachin     | Tendulkar | sachin@abc.com | India   |
|  6 | Virat      | Kohli     | virat@abc.com  | India   |
|  7 | rohit      | NULL      | rohit@abc.com  | India   |
+----+------------+-----------+----------------+---------+
3 rows in set (0.00 sec)


SQL Where Clause – Interview Questions

Q 1: What is the WHERE clause used for?

Ans: WHERE filters records based on specified conditions.

Q 2: Can WHERE be used with SELECT, UPDATE, and DELETE?

Ans: Yes, it can be used with all these statements.

Q 3: What happens if WHERE is omitted?

Ans: All rows are affected.

Q 4: Can multiple conditions be used in WHERE?

Ans: Yes, using logical operators like AND and OR.

Q 5: Is WHERE mandatory in SELECT?

Ans: No, it is optional.

SQL Where Clause – Objective Questions (MCQs)

Q1. Which clause is used to filter records based on a condition?






Q2. WHERE clause can be used with which statements?






Q3. Which operator is used to combine multiple conditions in WHERE?






Q4. Which condition checks for a range of values?






Q5. WHERE clause cannot be used with:






Related SQL Where Clause Topics