Professional Documents
Culture Documents
int(10),name
varchar(20),gender
+--------+-------------+------+-----+--------+-------+
| id
| int(10)
| NO | PRI | 0
|
|
| name | varchar(20) | YES |
| NULL |
|
| gender | varchar(10) | YES |
| NULL |
|
| email | varchar(20) | YES |
| NULL |
|
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select * from student;
+-----+-----------+--------+-------+
| id | name
| gender | email |
+-----+-----------+--------+-------+
| 224 | mohanraj | male | NULL |
| 225 | karthi | male | NULL |
| 226 | jayashree | female | NULL |
+-----+-----------+--------+-------+
3 rows in set (0.00 sec)
How to update the data?
mysql> update student set email='raj@gmail.com' where id=224;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update student set email='karthi@gmail.com' where id=225;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update student set email='jayashree@gmail.com' where id=226;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from student;
+-----+-----------+--------+---------------------+
| id | name
| gender | email
|
+-----+-----------+--------+---------------------+
| 224 | mohanraj | male | raj@gmail.com
|
| 225 | karthi | male | karthi@gmail.com |
| 226 | jayashree | female | jayashree@gmail.com |
+-----+-----------+--------+---------------------+
3 rows in set (0.00 sec)
After updating how to insert the data?
mysql> insert into student values(227,'venu','female','venu@gmail.com');
Query OK, 1 row affected (0.00 sec)
mysql> select * from student;
+-----+-----------+--------+---------------------+
| id | name
| gender | email
|
+-----+-----------+--------+---------------------+
| 224 | mohanraj | male | raj@gmail.com
|
| 225 | karthi | male | karthi@gmail.com |
| 226 | jayashree | female | jayashree@gmail.com |
| 227 | venu
| female | venu@gmail.com
|
+-----+-----------+--------+---------------------+
4 rows in set (0.00 sec)
How to delete the data?
mysql> delete from student where id=227;
Query OK, 1 row affected (0.00 sec)
mysql> select * from student;
+-----+-----------+--------+---------------------+
| id | name
| gender | email
|
+-----+-----------+--------+---------------------+
| 224 | mohanraj | male | raj@gmail.com
|
| 225 | karthi | male | karthi@gmail.com |
| 226 | jayashree | female | jayashree@gmail.com |
+-----+-----------+--------+---------------------+
3 rows in set (0.00 sec)
How to use like ?
mysql> select * from student where name like 'ja%';
+-----+-----------+--------+---------------------+
| id | name
| gender | email
|
+-----+-----------+--------+---------------------+
| 226 | jayashree | female | jayashree@gmail.com |
+-----+-----------+--------+---------------------+
+-------------+
| count(name) |
+-------------+
|
1|
|
2|
+-------------+
2 rows in set (0.01 sec)
mysql> select count(name) from student group by name;
+-------------+
| count(name) |
+-------------+
|
1|
|
1|
|
1|
+-------------+
3 rows in set (0.00 sec)
mysql> alter table student add column fee int(10);
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> update student set fee=1000 where id=224;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update student set fee=2000 where id=225;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update student set fee=3000 where id=226;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
AVERAGE:
mysql> select avg(fee) from student;
+-----------+
| avg(fee) |
+-----------+
| 2500.0000 |
+-----------+
1 row in set (0.00 sec)
MINIMUM:
mysql> select min(fee) from student;
+----------+
| min(fee) |
+----------+
| 1000 |
+----------+
1 row in set (0.00 sec)
MAXIMUM:
mysql> select max(fee) from student;
+----------+
| max(fee) |
+----------+
| 4000 |
+----------+
1 row in set (0.00 sec)
-------------------------------------------------------------------------------------------JOINS:
mysql> create table emp(eid int(10),ename varchar(20),salary int(10));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into emp values(223,'mohanraj',20000);
Query OK, 1 row affected (0.00 sec)
mysql> insert into emp values(224,'fizur',25000);
Query OK, 1 row affected (0.00 sec)
+-----+-----------+--------+--------+
3 rows in set (0.00 sec)
mysql> select * from emp;
+------+----------+--------+
| eid | ename | salary |
+------+----------+--------+
| 223 | mohanraj | 20000 |
| 224 | fizur | 25000 |
| 225 | Rizwan | 25000 |
| 226 | selvi | 23000 |
+------+----------+--------+
4 rows in set (0.00 sec)
Timestamp in Mysql
mysql> select sysdate();
+---------------------+
| sysdate()
|
+---------------------+
| 2009-07-30 18:23:08 |
+---------------------+
1 row in set (0.02 sec)
Date in Mysql
mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2009-07-30 |
+------------+
1 row in set (0.00 sec)
Time in Mysql
mysql> select utc_time();
+------------+
| utc_time() |
+------------+
| 13:00:40 |
+------------+
1 row in set (0.01 sec)
AND and OR :
mysql> select * from student where name='mohanraj' or name='karthi';
+-----+----------+--------+------------------+------+
| id | name | gender | email
| fee |
+-----+----------+--------+------------------+------+
| 224 | mohanraj | male | raj@gmail.com | 1000 |
| 225 | karthi | male | karthi@gmail.com | 2000 |
+-----+----------+--------+------------------+------+
2 rows in set (0.00 sec)
mysql> select *
name='karthi';
Empty set (0.00 sec)
from
student
where
name='mohanraj'
and
mysql> select *
email='karthi';
Empty set (0.00 sec)
from
student
where
name='mohanraj'
and
and
IN:
mysql>insert into student
values(229,'laxmi','female','laxmi@gmail.com',1000);
Query OK, 1 row affected (0.00 sec)
mysql> insert into student
values(230,'rajini','male','rajini@gmail.com',2000);