What is WHERE clause in SQL?
The WHERE condition is used to filter the records and fetching only the necessary records. A condition need to specify while retrieving the data from table. If the given condition is satisfied, then only it returns a specific data from the table. The WHERE condition is used in SELECT, UPDATE and DELETE statement. You can specify a condition using the comparison and logical operator.
Syntax of WHERE clause
Following is the syntax of where clause, it gives you an idea about, how you can use while writing SQL query.
SELECT * FROM table_name WHERE [condition];
Examples of WHERE clause
For following examples used student table, below is the data from student table. Each example is make for comparison and logical operator.
1) Equal To : Fetch the data from student table where student name is Joan
2) Greater Than : Fetch the data from student table where student roll number greater than 1.
3) Less Than : Fetch the data from student table where student roll number less than 3.
4) Greater Than or Equal To : Fetch the data from student table where student roll number greater than or equal to 3.
5) Less Than or Equal To : Fetch the data from student table where student roll number less than or equal to 3.
6) Not Equal to : Fetch the data from student table where student roll number not equal to 3.