You are on page 1of 3

mysql> show databases;

+--------------------+
| Database |
+--------------------+
| advik |
| employee |
| information_schema |
| mysql |
| performance_schema |
| school |
| sys |
+--------------------+
7 rows in set (0.02 sec)

mysql> use school;


Database changed
mysql> create table Employee(Empid int,EmpName varchar(100),Department
varchar(100),ContactNo int,EmailId varchar(100),EmpHeadId int);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into
Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(101,'ISHA','E-
101',1234567890,'isha@gmail.com',105);
Query OK, 1 row affected (0.02 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(102,'PRIYA','E
-104',1234567890,'priya@yahoo.com',101);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(103,'NEHA','E-
101',1234567890,'neha@gmail.com',101);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(104,'RAHUL','E
-102',1234567890,'rahul@yahoo.com',105);
Query OK, 1 row affected (0.01 sec)

mysql> insert into


Employee(Empid,Empname,Department,ContactNo,EmailId,EmpHeadId)values(105,'ABHISHEK'
,'E-101',1234567890,'abhishek@gmail.com',102);
Query OK, 1 row affected (0.01 sec)

mysql> select * from Employee;


+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 101 | ISHA | E-101 | 1234567890 | isha@gmail.com | 105 |
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+
5 rows in set (0.00 sec)

mysql> select EmpName from Employee order by EmpName DESC;


+----------+
| EmpName |
+----------+
| RAHUL |
| PRIYA |
| NEHA |
| ISHA |
| ABHISHEK |
+----------+
5 rows in set (0.01 sec)

mysql> select * from Employee where EmpName like('P%');


+-------+---------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+---------+------------+------------+-----------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
+-------+---------+------------+------------+-----------------+-----------+
1 row in set (0.00 sec)

mysql> select * from Employee where Department='E-104' or Department='E-102';


+-------+---------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+---------+------------+------------+-----------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
+-------+---------+------------+------------+-----------------+-----------+
2 rows in set (0.00 sec)

mysql> select EmpName from Employee where EmpName like ('%A');


+---------+
| EmpName |
+---------+
| ISHA |
| PRIYA |
| NEHA |
+---------+
3 rows in set (0.00 sec)
mysql> select * from Employee where EmpId=104 and EmpHeadId=105;
+-------+---------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+---------+------------+------------+-----------------+-----------+
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
+-------+---------+------------+------------+-----------------+-----------+
1 row in set (0.00 sec)
mysql> select * from Employee where EmailId like ('__H%');
+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 101 | ISHA | E-101 | 1234567890 | isha@gmail.com | 105 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-102 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+

mysql>
mysql> select * from Employee where EmailId like ('%gmail.com');
+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 101 | ISHA | E-101 | 1234567890 | isha@gmail.com | 105 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+
3 rows in set (0.00 sec)

mysql> delete from employee where Department =('E-104');


Query OK, 1 row affected (0.00 sec)

mysql> select * from employee;


+-------+----------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+-----------------+-----------+
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-111 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | ts123@gmail.com | 102 |
+-------+----------+------------+------------+-----------------+-----------+
3 rows in set (0.00 sec)
mysql> update employee set Department=('E-111') where EmpHeadId=('105');
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from employee;


+-------+----------+------------+------------+--------------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+--------------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-111 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | abhishek@gmail.com | 102 |
+-------+----------+------------+------------+--------------------+-----------+

mysql> update Employee set EmailId=('ts123@gmail.com') where EmpName=('ABHISHEK');


Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from employee;


+-------+----------+------------+------------+-----------------+-----------+
| Empid | EmpName | Department | ContactNo | EmailId | EmpHeadId |
+-------+----------+------------+------------+-----------------+-----------+
| 102 | PRIYA | E-104 | 1234567890 | priya@yahoo.com | 101 |
| 103 | NEHA | E-101 | 1234567890 | neha@gmail.com | 101 |
| 104 | RAHUL | E-111 | 1234567890 | rahul@yahoo.com | 105 |
| 105 | ABHISHEK | E-101 | 1234567890 | ts123@gmail.com | 102 |
+-------+----------+------------+------------+-----------------+-----------+
4 rows in set (0.00 sec)

You might also like