Home >>MySQL Tutorial >MySQL Where Clause
The WHERE clause is used to extract only those records that fulfill a specified condition. where clause is a part of select command . it is used to fetch data from a table . we basically use this clause to filter out our results. by using where clause we can select particular set of records based specified condition. Syntax
SELECT column_name(s) FROM table_name WHERE column_name = value
The following example selects all data from the "empInfo" table where email='devesh@gmail.com'
<?php //connect database $con=mysqli_connect("localhost","root","","Employee") or die(mysqli_error()); //select values from empInfo table where column=value $data="SELECT * FROM empInfo where emp_id='devesh@gmail.com'"; $val=mysqli_query($con,$data); echo "<table border='1'>"; echo "<tr><th>Emp_id</th><th>Name</th><th>Email</th><th>Mobile</th></tr>"; while(list($id,$name,$eid,$mob) = mysqli_fetch_array($val)) { echo "<tr>"; echo "<td>".$id."</td>"; echo "<td>".$name."</td>"; echo "<td>".$eid."</td>"; echo "<td>".$mob."</td>"; echo "</tr>"; } echo "</table>"; ?>
Output :
Emp_id | Name | Mobile | |
---|---|---|---|
1 | devesh | devesh@gmail.com | 9910099100 |
In above example first of all we make connection with the database after that select query is used to search various records and a where clause is given according to which , wherever emp_id matches with devesh@gmail.com all the fields of that particular record are shown in tabular form.