SQL WHERE Clause
The WHERE clause is a search filter that returns only true records. The WHERE clause chooses the selected records based on the given conditions. The WHERE clause is used with the queries to filter the data from billions or trillions of records. This clause is an optional part of a SELECT query, the DELETE query, and the UPDATE query.
For example, you have thousands of records on the college record track from college, and you want a final year students list of computer department, then you will use a search bar to list out computer department final year students. In the same way, the database uses the WHERE clause to search the records from the tables.
The WHERE clause syntax with the SELECT statement is as follows:
SELECT * FROM Table_Name WHERE conditions;
The Where clause in the SELECT statement is used to fetch the records from the table, but if you want to change specific records or eliminate the specific records from the table, you can use the WHERE clause in the UPDATE statement and DELETE statement.
The WHERE clause syntax with the UPDATE statement is as follows:
UPDATE Table_Name SET Column_Name = values WHERE conditions;
The WHERE clause syntax with the DELETE statement is as follows:
DELETE FROM Table_Name WHERE conditions;
Let’s understand the SQL WHERE Clause with the help of examples.
Assume the following table, which has certain data.
Table Name: D_Students
Student_Id | Student_Name | First_ Semester | Second_ Semester | Third_ Semester | Fourth_ Semester | Fifth_ Semester | Sixth_ Semester | Total | Department_ Id |
202111 | Vaishnavi Patil | 94 | 91 | 88 | 85 | 95 | 92 | 91 | 6 |
202112 | Vaibhav Lokhande | 85 | 90 | 92 | 80 | 85 | 82 | 86 | 2 |
202113 | Yash Dhull | 90 | 88 | 94 | 87 | 85 | 90 | 89 | 3 |
202114 | Sonali Patole | 95 | 90 | 92 | 88 | 92 | 90 | 91 | 4 |
202115 | Axar Patel | 85 | 80 | 82 | 86 | 92 | 84 | 85 | 1 |
202116 | Meena Mishra | 78 | 75 | 80 | 74 | 85 | 77 | 78 | 3 |
202117 | Mahesh Kumbhar | 75 | 80 | 75 | 78 | 80 | 76 | 77 | 5 |
202118 | Sakshi Patil | 80 | 78 | 74 | 78 | 80 | 77 | 78 | 2 |
202119 | Sopan Bhore | 70 | 68 | 75 | 75 | 80 | 80 | 75 | 2 |
202220 | Prajwal Lokhande | 80 | 85 | 85 | 75 | 78 | 80 | 81 | 4 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 7 |
202222 | Venkatesh Iyer | 90 | 89 | 87 | 90 | 92 | 91 | 90 | 3 |
202223 | Anushka Sen | 70 | 75 | 71 | 74 | 80 | 78 | 75 | 1 |
202224 | Aakash Jain | 80 | 75 | 72 | 74 | 85 | 80 | 78 | 7 |
202225 | Akshay Agarwal | 85 | 80 | 78 | 88 | 90 | 82 | 84 | 7 |
202226 | Shwetali Bhagwat | 90 | 80 | 85 | 88 | 90 | 80 | 86 | 6 |
202227 | Mayuri Wagh | 80 | 80 | 85 | 80 | 82 | 85 | 82 | 4 |
202228 | Utkarsh Rokade | 85 | 80 | 80 | 90 | 84 | 84 | 84 | 5 |
202229 | Manthan Koli | 85 | 75 | 84 | 78 | 82 | 80 | 81 | 2 |
202230 | Mayur Jain | 80 | 88 | 87 | 90 | 92 | 90 | 88 | 1 |
Example 1: Write a query to fetch student information from the D_Students table where the First_Semester percentage is 85:
SELECT * FROM D_Students WHERE First_Semester = 85;
In the above WHERE clause example, we have displayed the student's information from the table whose first_semester percentage is 85.
The following output is as follows:
Student_Id | Student_Name | First_ Semester | Second_ Semester | Third_ Semester | Fourth_ Semester | Fifth_ Semester | Sixth_ Semester | Total | Department_ Id |
202112 | Vaibhav Lokhande | 85 | 90 | 92 | 80 | 85 | 82 | 86 | 2 |
202115 | Axar Patel | 85 | 80 | 82 | 86 | 92 | 84 | 85 | 1 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 7 |
202225 | Akshay Agarwal | 85 | 80 | 78 | 88 | 90 | 82 | 84 | 7 |
202228 | Utkarsh Rokade | 85 | 80 | 80 | 90 | 84 | 84 | 84 | 5 |
202229 | Manthan Koli | 85 | 75 | 84 | 78 | 82 | 80 | 81 | 2 |

Example 2: Write a query to fetch student information from the D_Students table where First_Semester percentage is 85 or Sixth_Semester percentage is greater than 80:
SELECT * FROM D_Students WHERE First_Semester = 85 OR Sixth_Semester > 80;
In the above WHERE clause example, we have displayed the student's information from the table whose first_semester percentage is 85 or sixth_semester percentage is greater than 80.
The following output is as follows:
Student_Id | Student_Name | First_ Semester | Second_ Semester | Third_ Semester | Fourth_ Semester | Fifth_ Semester | Sixth_ Semester | Total | Department_ Id |
202111 | Vaishnavi Patil | 94 | 91 | 88 | 85 | 95 | 92 | 91 | 6 |
202112 | Vaibhav Lokhande | 85 | 90 | 92 | 80 | 85 | 82 | 86 | 2 |
202113 | Yash Dhull | 90 | 88 | 94 | 87 | 85 | 90 | 89 | 3 |
202114 | Sonali Patole | 95 | 90 | 92 | 88 | 92 | 90 | 91 | 4 |
202115 | Axar Patel | 85 | 80 | 82 | 86 | 92 | 84 | 85 | 1 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 7 |
202222 | Venkatesh Iyer | 90 | 89 | 87 | 90 | 92 | 91 | 90 | 3 |
202225 | Akshay Agarwal | 85 | 80 | 78 | 88 | 90 | 82 | 84 | 7 |
202227 | Mayuri Wagh | 80 | 80 | 85 | 80 | 82 | 85 | 82 | 4 |
202228 | Utkarsh Rokade | 85 | 80 | 80 | 90 | 84 | 84 | 84 | 5 |
202229 | Manthan Koli | 85 | 75 | 84 | 78 | 82 | 80 | 81 | 2 |
202230 | Mayur Jain | 80 | 88 | 87 | 90 | 92 | 90 | 88 | 1 |

Example 3: Write a query to modify the student’s information from the D_Students table where the student total percentage is less than 85.
UPDATE D_Students SET Total = Total + 5 WHERE Total < 85;
In the above WHERE clause example, we have modified the student’s information from the table whose total percentage is less than 85.
We will verify whether the record is successfully modified or not by executing the below query:
SELECT * FROM D_Students;
The following output is as follows:
Student_Id | Student_Name | First_ Semester | Second_ Semester | Third_ Semester | Fourth_ Semester | Fifth_ Semester | Sixth_ Semester | Total | Department_ Id |
202111 | Vaishnavi Patil | 94 | 91 | 88 | 85 | 95 | 92 | 91 | 6 |
202112 | Vaibhav Lokhande | 85 | 90 | 92 | 80 | 85 | 82 | 86 | 2 |
202113 | Yash Dhull | 90 | 88 | 94 | 87 | 85 | 90 | 89 | 3 |
202114 | Sonali Patole | 95 | 90 | 92 | 88 | 92 | 90 | 91 | 4 |
202115 | Axar Patel | 85 | 80 | 82 | 86 | 92 | 84 | 85 | 1 |
202116 | Meena Mishra | 78 | 75 | 80 | 74 | 85 | 77 | 83 | 3 |
202117 | Mahesh Kumbhar | 75 | 80 | 75 | 78 | 80 | 76 | 82 | 5 |
202118 | Sakshi Patil | 80 | 78 | 74 | 78 | 80 | 77 | 83 | 2 |
202119 | Sopan Bhore | 70 | 68 | 75 | 75 | 80 | 80 | 80 | 2 |
202220 | Prajwal Lokhande | 80 | 85 | 85 | 75 | 78 | 80 | 86 | 4 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 7 |
202222 | Venkatesh Iyer | 90 | 89 | 87 | 90 | 92 | 91 | 90 | 3 |
202223 | Anushka Sen | 70 | 75 | 71 | 74 | 80 | 78 | 80 | 1 |
202224 | Aakash Jain | 80 | 75 | 72 | 74 | 85 | 80 | 83 | 7 |
202225 | Akshay Agarwal | 85 | 80 | 78 | 88 | 90 | 82 | 89 | 7 |
202226 | Shwetali Bhagwat | 90 | 80 | 85 | 88 | 90 | 80 | 86 | 6 |
202227 | Mayuri Wagh | 80 | 80 | 85 | 80 | 82 | 85 | 87 | 4 |
202228 | Utkarsh Rokade | 85 | 80 | 80 | 90 | 84 | 84 | 89 | 5 |
202229 | Manthan Koli | 85 | 75 | 84 | 78 | 82 | 80 | 86 | 2 |
202230 | Mayur Jain | 80 | 88 | 87 | 90 | 92 | 90 | 88 | 1 |

Example 4: Write a query to modify the student's information from the D_Students table where the student Second_Semester percentage is 80.
UPDATE D_Students SET Second_Semester = 83 WHERE Second_Semester = 80;
In the above WHERE clause example, we have modified the student’s information from the table whose second_semester percentage is 80.
We will verify whether the record is successfully modified or not by executing the below query:
SELECT * FROM D_Students;
The following output is as follows:
Student_Id | Student_Name | First_ Semester | Second_ Semester | Third_ Semester | Fourth_ Semester | Fifth_ Semester | Sixth_ Semester | Total | Department_ Id |
202111 | Vaishnavi Patil | 94 | 91 | 88 | 85 | 95 | 92 | 91 | 6 |
202112 | Vaibhav Lokhande | 85 | 90 | 92 | 80 | 85 | 82 | 86 | 2 |
202113 | Yash Dhull | 90 | 88 | 94 | 87 | 85 | 90 | 89 | 3 |
202114 | Sonali Patole | 95 | 90 | 92 | 88 | 92 | 90 | 91 | 4 |
202115 | Axar Patel | 85 | 83 | 82 | 86 | 92 | 84 | 85 | 1 |
202116 | Meena Mishra | 78 | 75 | 80 | 74 | 85 | 77 | 83 | 3 |
202117 | Mahesh Kumbhar | 75 | 83 | 75 | 78 | 80 | 76 | 82 | 5 |
202118 | Sakshi Patil | 80 | 78 | 74 | 78 | 80 | 77 | 83 | 2 |
202119 | Sopan Bhore | 70 | 68 | 75 | 75 | 80 | 80 | 80 | 2 |
202220 | Prajwal Lokhande | 80 | 85 | 85 | 75 | 78 | 80 | 86 | 4 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 7 |
202222 | Venkatesh Iyer | 90 | 89 | 87 | 90 | 92 | 91 | 90 | 3 |
202223 | Anushka Sen | 70 | 75 | 71 | 74 | 80 | 78 | 80 | 1 |
202224 | Aakash Jain | 80 | 75 | 72 | 74 | 85 | 80 | 83 | 7 |
202225 | Akshay Agarwal | 85 | 83 | 78 | 88 | 90 | 82 | 89 | 7 |
202226 | Shwetali Bhagwat | 90 | 83 | 85 | 88 | 90 | 80 | 86 | 6 |
202227 | Mayuri Wagh | 80 | 83 | 85 | 80 | 82 | 85 | 87 | 4 |
202228 | Utkarsh Rokade | 85 | 83 | 80 | 90 | 84 | 84 | 89 | 5 |
202229 | Manthan Koli | 85 | 75 | 84 | 78 | 82 | 80 | 86 | 2 |
202230 | Mayur Jain | 80 | 88 | 87 | 90 | 92 | 90 | 88 | 1 |

Example 5: Write a query to remove the student's information from the D_Students table where the student Second_Semester percentage is 83.
DELETE FROM D_Students WHERE Second_Semester = 83;
In the above WHERE clause example, we have deleted the student’s information from the table whose second_semester percentage is 83.
We will verify whether the record is successfully removed or not by executing the below query:
SELECT * FROM D_Students;
The following output is as follows:
Student_Id | Student_Name | First_ Semester | Second_ Semester | Third_ Semester | Fourth_ Semester | Fifth_ Semester | Sixth_ Semester | Total | Department_ Id |
202111 | Vaishnavi Patil | 94 | 91 | 88 | 85 | 95 | 92 | 91 | 6 |
202112 | Vaibhav Lokhande | 85 | 90 | 92 | 80 | 85 | 82 | 86 | 2 |
202113 | Yash Dhull | 90 | 88 | 94 | 87 | 85 | 90 | 89 | 3 |
202114 | Sonali Patole | 95 | 90 | 92 | 88 | 92 | 90 | 91 | 4 |
202116 | Meena Mishra | 78 | 75 | 80 | 74 | 85 | 77 | 83 | 3 |
202118 | Sakshi Patil | 80 | 78 | 74 | 78 | 80 | 77 | 83 | 2 |
202119 | Sopan Bhore | 70 | 68 | 75 | 75 | 80 | 80 | 80 | 2 |
202220 | Prajwal Lokhande | 80 | 85 | 85 | 75 | 78 | 80 | 86 | 4 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 7 |
202222 | Venkatesh Iyer | 90 | 89 | 87 | 90 | 92 | 91 | 90 | 3 |
202223 | Anushka Sen | 70 | 75 | 71 | 74 | 80 | 78 | 80 | 1 |
202224 | Aakash Jain | 80 | 75 | 72 | 74 | 85 | 80 | 83 | 7 |
202229 | Manthan Koli | 85 | 75 | 84 | 78 | 82 | 80 | 86 | 2 |
202230 | Mayur Jain | 80 | 88 | 87 | 90 | 92 | 90 | 88 | 1 |

Example 6: Write a query to remove the student's information from the D_Students table where the student department id is 2.
DELETE FROM D_Students WHERE Department_Id = 2;
In the above WHERE clause example, we have deleted the student’s information from the table whose department id is 2.
We will verify whether the record is successfully removed or not by executing the below query:
SELECT * FROM D_Students;
The following output is as follows:
Student_Id | Student_Name | First_ Semester | Second_ Semester | Third_ Semester | Fourth_ Semester | Fifth_ Semester | Sixth_ Semester | Total | Department_ Id |
202111 | Vaishnavi Patil | 94 | 91 | 88 | 85 | 95 | 92 | 91 | 6 |
202113 | Yash Dhull | 90 | 88 | 94 | 87 | 85 | 90 | 89 | 3 |
202114 | Sonali Patole | 95 | 90 | 92 | 88 | 92 | 90 | 91 | 4 |
202116 | Meena Mishra | 78 | 75 | 80 | 74 | 85 | 77 | 83 | 3 |
202220 | Prajwal Lokhande | 80 | 85 | 85 | 75 | 78 | 80 | 86 | 4 |
202221 | Anuja Wanare | 85 | 88 | 86 | 82 | 84 | 85 | 85 | 7 |
202222 | Venkatesh Iyer | 90 | 89 | 87 | 90 | 92 | 91 | 90 | 3 |
202223 | Anushka Sen | 70 | 75 | 71 | 74 | 80 | 78 | 80 | 1 |
202224 | Aakash Jain | 80 | 75 | 72 | 74 | 85 | 80 | 83 | 7 |
202230 | Mayur Jain | 80 | 88 | 87 | 90 | 92 | 90 | 88 | 1 |
