Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 5.0.13-rc-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
| Database |
+--------------------+
| information_schema |
| college |
| dba |
| mba |
| mysql |
| sink |
| test |
7 rows in set (0.02 sec)
mysql> create database hostel;
Query OK, 1 row affected (0.06 sec)
mysql> use hostel;
Database changed
mysql> create table students(name varchar(20),rollno int,address varchar(20),id
int,fee int);
Query OK, 0 rows affected (0.14 sec)
mysql> desc students;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| rollno | int(11) | YES | | NULL | |
| address | varchar(20) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| fee | int(11) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
mysql> insert into students values('arun',101,'del',3100,50000);
Query OK, 1 row affected (0.06 sec)
mysql> insert into students values('aru',102,'del',3110,51000);
Query OK, 1 row affected (0.08 sec)
mysql> insert into students values('paul',103,'fbd',3111,51100);
Query OK, 1 row affected (0.11 sec)
mysql> insert into students values('mik',104,'hr',3114,51110);
Query OK, 1 row affected (0.06 sec)
mysql> insert into students values('daniel',105,'punjab',3101,50000);
Query OK, 1 row affected (0.08 sec)
mysql> select * from students;
| name | rollno | address | id | fee |
+--------+--------+---------+------+-------+
| arun | 101 | del | 3100 | 50000 |
| aru | 102 | del | 3110 | 51000 |
| paul | 103 | fbd | 3111 | 51100 |
| mik | 104 | hr | 3114 | 51110 |
| daniel | 105 | punjab | 3101 | 50000 |
5 rows in set (0.02 sec)
mysql> select name from students where rollno = 104;
| name |
+------+
| mik |
1 row in set (0.00 sec)
mysql> select name from students where(not id = 104);
| name |
+--------+
| arun |
| aru |
| paul |
| mik |
| daniel |
+--------+
5 rows in set (0.00 sec)
mysql> select name from students where fee between 50000 and 51100;
| name |
+--------+
| arun |
| aru |
| paul |
| daniel |
4 rows in set (0.01 sec)
mysql> select * from students where fee between 50000 and 51100;
| name | rollno | address | id | fee |
+--------+--------+---------+------+-------+
| arun | 101 | del | 3100 | 50000 |
| aru | 102 | del | 3110 | 51000 |
| paul | 103 | fbd | 3111 | 51100 |
| daniel | 105 | punjab | 3101 | 50000 |
+--------+--------+---------+------+-------+
4 rows in set (0.00 sec)
mysql> select * from students where address in('del','fbd');
+------+--------+---------+------+-------+
| name | rollno | address | id | fee |
+------+--------+---------+------+-------+
| arun | 101 | del | 3100 | 50000 |
| aru | 102 | del | 3110 | 51000 |
| paul | 103 | fbd | 3111 | 51100 |
3 rows in set (0.00 sec)
mysql> select * from students where name like 'a%';
| name | rollno | address | id | fee |
+------+--------+---------+------+-------+
| arun | 101 | del | 3100 | 50000 |
| aru | 102 | del | 3110 | 51000 |
2 rows in set (0.00 sec)
mysql> select * from students where name like '%l%';
| name | rollno | address | id | fee |
+--------+--------+---------+------+-------+
| paul | 103 | fbd | 3111 | 51100 |
| daniel | 105 | punjab | 3101 | 50000 |
2 rows in set (0.00 sec)
mysql> select * from students where name like '___';
| name | rollno | address | id | fee |
+------+--------+---------+------+-------+
| aru | 102 | del | 3110 | 51000 |
| mik | 104 | hr | 3114 | 51110 |
2 rows in set (0.00 sec)
mysql> select * from students where name like '____';
| name | rollno | address | id | fee |
+------+--------+---------+------+-------+
| arun | 101 | del | 3100 | 50000 |
| paul | 103 | fbd | 3111 | 51100 |
2 rows in set (0.00 sec)
mysql> select * from students order by id desc;
| name | rollno | address | id | fee |
+--------+--------+---------+------+-------+
| mik | 104 | hr | 3114 | 51110 |
| paul | 103 | fbd | 3111 | 51100 |
| aru | 102 | del | 3110 | 51000 |
| daniel | 105 | punjab | 3101 | 50000 |
| arun | 101 | del | 3100 | 50000 |
5 rows in set (0.00 sec)
mysql> select * from students order by fee asc;
| name | rollno | address | id | fee |
+--------+--------+---------+------+-------+
| arun | 101 | del | 3100 | 50000 |
| daniel | 105 | punjab | 3101 | 50000 |
| aru | 102 | del | 3110 | 51000 |
| paul | 103 | fbd | 3111 | 51100 |
| mik | 104 | hr | 3114 | 51110 |
5 rows in set (0.00 sec)
mysql> select sqrt(9);
| sqrt(9) |
+---------+
| 3|
1 row in set (0.08 sec)
mysql> select mod(11,3);
| mod(11,3) |
+-----------+
| 2|
1 row in set (0.00 sec)
mysql> select power(2,3);
| power(2,3) |
+------------+
| 8|
1 row in set (0.05 sec)
mysql> select round(15.193,2);
| round(15.193,2) |
+-----------------+
| 15.19 |
1 row in set (0.05 sec)
mysql> select truncate (15.798,1);
| truncate (15.798,1) |
+---------------------+
| 15.7 |
1 row in set (0.00 sec)
mysql> select curdate();
| curdate() |
+------------+
| 2011-05-04 |
1 row in set (0.02 sec)
mysql> select curtime();
| curtime() |
+-----------+
| 14:38:00 |
1 row in set (0.06 sec)
mysql> select now();
| now() |
+---------------------+
| 2011-05-04 14:38:15 |
1 row in set (0.00 sec)
mysql> select dayname('2011-4-18');
| dayname('2011-4-18') |
+----------------------+
| Monday |
1 row in set (0.00 sec)
mysql> select char(70,65,67,69);
| char(70,65,67,69) |
+-------------------+
| FACE |
1 row in set (0.00 sec)
mysql> select sum(fee) from students;
| sum(fee) |
+----------+
| 253210 |
1 row in set (0.01 sec)
mysql> select avg(fee) from students;
| avg(fee) |
+------------+
| 50642.0000 |
1 row in set (0.00 sec)
mysql> select max(fee) from students;
| max(fee) |
+----------+
| 51110 |
1 row in set (0.00 sec)
mysql> select min(fee) from students;
| min(fee) |
+----------+
| 50000 |
1 row in set (0.01 sec)
mysql> select concat(address,name,fee) from students;
+--------------------------+
| concat(address,name,fee) |
+--------------------------+
| delarun50000 |
| delaru51000 |
| fbdpaul51100 |
| hrmik51110 |
| punjabdaniel50000 |
+--------------------------+
5 rows in set (0.00 sec)
mysql> select ucase(name) from students;
| ucase(name) |
+-------------+
| ARUN |
| ARU |
| PAUL |
| MIK |
| DANIEL |
5 rows in set (0.00 sec)
mysql> select lcase(name) from students;
| lcase(name) |
+-------------+
| arun |
| aru |
| paul |
| mik |
| daniel |
5 rows in set (0.00 sec)
mysql> select substr('rahul',3,3);
| substr('rahul',3,3) |
+---------------------+
| hul |
1 row in set (0.02 sec)
mysql> select substr('daniel',2,3);
| substr('daniel',2,3) |
+----------------------+
| ani |
1 row in set (0.01 sec)
mysql> select instr('gaurav','a');
| instr('gaurav','a') |
+---------------------+
| 2|
1 row in set (0.00 sec)
mysql> select count(name) from students;
| count(name) |
+-------------+
| 5|
1 row in set (0.02 sec)
mysql> select length('choudhary');
| length('choudhary') |
+---------------------+
| 9|
1 row in set (0.00 sec)
mysql> select 4*3;
| 4*3 |
+-----+
| 12 |
1 row in set (0.00 sec)
mysql> select ltrim('rahul');
+----------------+
| ltrim('rahul') |
+----------------+
| rahul |
+----------------+
1 row in set (0.00 sec)
mysql> select * from age_information order by lastname;
| lastname | firstname | age |
+-----------+-----------+------+
| choudhary | gaurav | 25 |
| gaurav | sushant | 27 |
| gupta | rahul | 24 |
3 rows in set (0.02 sec)
mysql> update age_information set age = 28 where lastname = 'gaurav';
Query OK, 1 row affected (0.41 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from age_information;
| lastname | firstname | age |
+-----------+-----------+------+
| choudhary | gaurav | 25 |
| gupta | rahul | 24 |
| gaurav | sushant | 28 |
3 rows in set (0.02 sec)
mysql> delete from age_information where lastname='gupta';
Query OK, 1 row affected (0.08 sec)
mysql> alter table age_information drop address;
Query OK, 2 rows affected (0.28 sec)
mysql> alter table age_information add address varchar(20);
Query OK, 2 rows affected (0.28 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from age_information;
+----------+-----------+------+------+---------+
| lastname | firstname | age | fee | address |
+----------+-----------+------+------+---------+
| gupta | rahul | 25 | NULL | NULL |
| gaurav | sushant | 28 | NULL | NULL |
mysql> alter table age_information change fee amount varchar(20);
Query OK, 2 rows affected (0.20 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from age_information;
+----------+-----------+------+--------+
| lastname | firstname | age | amount |
+----------+-----------+------+--------+
| gaurav | sushant | 28 | NULL |
| NULL | NULL | NULL | NULL |
+----------+-----------+------+--------+
2 rows in set (0.02 sec)