Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Sql-functions Mysql where

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql where

Advertisement
Mysql Where is used to return the select records based on the condition specified in Where CLAUSE.

Mysql where

     

Mysql Where is used to return the select records based on the condition specified in Where CLAUSE.

Understand with Example

The Tutorial illustrate an example on 'Mysql Where'.To grasp this example we create a table 'MyTable' with required fieldnames and datatypes required.

Query for creating table:

 

 

 

The Query create table create a table 'MyTable'.

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 add the records or rows 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 given below return the empname record from mytable whose salary is 20000 as specified in WHERE Clause.

mysql> select empname from mytable where salary=20000;

Output:-

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

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 16, 2009

Related Tutorials

Discuss: Mysql where  

Post your Comment


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