The WHERE Clause is used to filter only those records that are fulfilled by a specific condition given by the user. in other words, the SQL WHERE clause is used to restrict the number of rows affected by a SELECT, UPDATE or DELETE query.
The basic syntax of the where clause is –
SELECT Column1 , Column2 , ….
Implementation of WHERE Clause :
Let us consider the following table “Data” with three columns ‘FirstName’, ‘LastName’ and ‘Age’.
To select all the rows where the “Firstname” is “ram”, we will use the following code :
Where Clause using Procedural Method :
Code Explanation :
- The “res” variable stores the data that is returned by the function mysql_query().
- Everytime mysqli_fetch_array() is invoked, it returns the next row from the res() set.
- The while loop is used to loop through all the rows of the table “data”.
Where Clause using Object Oriented Method :
Where Clause using PDO Method :
- Difference between Having clause and Group by clause
- PHP | MySQL ORDER BY Clause
- PHP | MySQL LIMIT Clause
- MySQL | PARTITION BY Clause
- MySQL | Common MySQL Queries
- SQL | Distinct Clause
- SQL | WHERE Clause
- SQL | SELECT TOP Clause
- SQL | Union Clause
- SQL | WITH clause
- SQL | Except Clause
- SQL | OFFSET-FETCH Clause
- SQL | LIMIT Clause
- SQL | Intersect & Except clause
- SQL | USING Clause
- SQL | With Ties Clause
- SQL | Sub queries in From Clause
- SQL | ON Clause
- Combining aggregate and non-aggregate values in SQL using Joins and Over clause
- SQL query using COUNT and HAVING clause
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.