Mysql Where Statement

Mysql Where Statement is useful when we want to return the records on the
basis of specified condition in Where Clause. The Where Clause restricts
the records and select only those records specified in it.
Understand with Example
The Tutorial illustrate an example from 'Mysql Where Statement'. To
understand and grasp this example we create a table 'employee' whose fieldnames
and datatypes are specified.
Create table "employee" :
CREATE TABLE `employee` (
`username` varchar(200) default NULL,
`emp_name` varchar(200) default NULL
) |
Describe the table "employee":
The Describe table is used to describe the fieldnames, datatypes,
Null, Key, Default etc of the table employee.
mysql> describe employee;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| username | varchar(200) | YES | | | |
| emp_name | varchar(200) | YES | | | |
+----------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec) |
Query to insert the record in table "employee":
The Query insert into is used to add the records or rows to the table 'employee'.
insert into employee (username,emp_name) values('vin','Vineet
Bansal')
insert into employee (username,emp_name) values('srbh','Saurabh');; |
Query to display the record of table "employee":
The Query select helps you to return the records from table
'employee'.
mysql> select * from employee;
+----------+---------------+
| username | emp_name |
+----------+---------------+
| srbh | Saurabh |
| vin | Vineet Bansal |
+----------+---------------+
2 rows in set (0.00 sec) |
Query to display the record of table "employee"
using "where" statement:
The Query Where Clause returns only those records from table
specified in Where Clause. In this example the table returns only those
records whose username is 'srbh' as specified in Where
Clause.
mysql> select * from employee where username='srbh';
+----------+----------+
| username | emp_name |
+----------+----------+
| srbh | Saurabh |
+----------+----------+
1 row in set (0.02 sec) |

|