Home Sql Mysql-example Mysql Where

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql Where

Advertisement
Mysql Where returns only those records from table which are specified in the WHERE Clause.

Mysql Where

     

Mysql Where returns only those records from table which are specified in the WHERE Clause. The Where Clause restricts the select query and shows you only the records specified in the Where Clause conditions.

Understand with Example

The Tutorial illustrate an example from 'Mysql Where', To understand an example we show you a demonstrative example that uses Where Clauses. The CREATE TABLE keyword creates a table 'Mytable' with required fieldnames and datatypes respectively. 

 

 

 

Query for creating table:

mysql> CREATE TABLE MyTable (
    ->              Empid int(10),
    ->              Empname varchar(60)
    ->              Salary int(90)
    ->            );
Query OK, 0 rows affected (0.13 sec)

Query for inserting data in table:

The Query insert into adds the records or rows value to the table 'MyTable'.

mysql>   insert into MyTable values(01,'Girish','20000');
Query OK, 1 row affected (0.02 sec)
mysql>     insert into MyTable values(02,'A','21000');
Query OK, 1 row affected (0.01 sec)
mysql>     insert into MyTable values(03,'C','22000');
Query OK, 1 row affected (0.00 sec)
mysql>     insert into MyTable values(04,'V','23000');
Query OK, 1 row affected (0.00 sec)
mysql>     insert into MyTable values(05,'B','24000');
Query OK, 1 row affected (0.00 sec)
mysql>     insert into MyTable values(06,'E','25000');
Query OK, 1 row affected (0.00 sec)
mysql>     insert into MyTable values(07,'Q','26000');
Query OK, 1 row affected (0.01 sec)
mysql>     insert into MyTable values(08,'W','27000');
Query OK, 1 row affected (0.01 sec)
mysql>     insert into MyTable values(09,'AS','28000');
Query OK, 1 row affected (0.00 sec)`

Query to view data inserted in table:

mysql> select * from mytable;
+-------+---------+--------+
| Empid | Empname | Salary |
+-------+---------+--------+
| 1     | Girish  | 20000  |
| 2     | A       | 21000  |
| 3     | C       | 22000  |
| 4     | V       | 23000  |
| 5     | B       | 24000  |
| 6     | E       | 25000  |
| 7     | Q       | 26000  |
| 8     | W       | 27000  |
| 9     | AS      | 28000  |
+-------+---------+--------+
9 rows in set (0.01 sec)

Query for using where clause:

The Query return only those records from 'mytable' that are specified in Where Clause. In this example the table returns records whose salary is 2000.

mysql> select empname from mytable where salary=20000;

Output:-

+---------+
| empname |
+---------+
| Girish  |
+---------+
1 row in set (0.03 sec)
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 17, 2009

Related Tutorials

Discuss: Mysql Where  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com