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 :
- PHP | MySQL LIMIT Clause
- PHP | MySQL ORDER BY Clause
- MySQL | PARTITION BY Clause
- Difference between Having clause and Group by clause
- MySQL | Common MySQL Queries
- SQL | Except Clause
- SQL | WITH clause
- SQL | WHERE Clause
- SQL | USING Clause
- SQL | ON Clause
- SQL | With Ties Clause
- SQL | Sub queries in From Clause
- SQL | LIMIT Clause
- SQL | Union Clause
- Having clause in MS SQL Server
- Where clause in MS SQL Server
- SQL | Distinct Clause
- SQL | SELECT TOP Clause
- Difference between Where and Having Clause in SQL
- Difference between From and Where Clause in SQL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.