mysql> use database1;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_database1 |
+---------------------+
| department |
| dependent |
| employee |
| project |
+---------------------+
4 rows in set (0.00 sec)
mysql> desc department;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| d_id | int | NO | PRI | NULL | |
| d_name | varchar(30) | YES | | NULL | |
| location | varchar(50) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
3 rows in set (0.06 sec)
mysql> desc dependent;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| relation | varchar(20) | NO | | NULL | |
| e_id | int | YES | MUL | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> desc employee;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| e_id | int | NO | PRI | NULL | auto_increment |
| e_name | varchar(25) | NO | | NULL | |
| address | varchar(20) | YES | | NULL | |
| doj | date | YES | | NULL | |
| d_id | int | YES | MUL | NULL | |
| p_id | int | YES | MUL | NULL | |
| contact_no | int | YES | UNI | NULL | |
| salary | int | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+
8 rows in set (0.04 sec)
mysql> desc project;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| p_id | int | NO | PRI | NULL | |
| p_name | varchar(30) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from employee;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
| 4 | Arvind | AIT PUNE | 2022-09-03 | 4000 | 4220 | 124124 | 25000 |
| 5 | Abhay | AIT PUNE | 2022-09-03 | 4000 | 4220 | 1235124 | 25000 |
| 7 | Shivank | AIT PUNE | 2022-09-03 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
4 rows in set (0.07 sec)
mysql> select * from employee where p_id=null;
Empty set (0.04 sec)
mysql> select * from employee where p_id is not null;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
| 4 | Ayush | AIT PUNE | 2022-09-03 | 4000 | 4220 | 124124 | 25000 |
| 5 | Dips | AIT PUNE | 2022-09-03 | 4000 | 4220 | 1235124 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
4 rows in set (0.04 sec)
mysql> select * from employee where salary>=20000;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
| 4 | Arvind | AIT PUNE | 2022-09-03 | 4000 | 4220 | 124124 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
4 rows in set (0.00 sec)
mysql> select * from employee where e_id>4;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 5 | Abhay | AIT PUNE | 2022-09-03 | 4000 | 4220 | 1235124 | 25000 |
| 7 | Shivank | AIT PUNE | 2022-09-03 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
2 rows in set (0.00 sec)
mysql> update employee
-> set doj='2022-04-03'
-> where e_id=4;
Query OK, 1 row affected (0.07 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update employee
-> set doj='2022-06-08'
-> where e_id=7;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update employee
-> set doj='2022-02-01'
-> where e_id=5;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from employee;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 25000 |
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 25000 |
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
4 rows in set (0.00 sec)
mysql> select * from employee where doj>'2022-03-01' and doj<'2022-07-01';
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 25000 |
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
2 rows in set (0.04 sec)
mysql> select * from employee where doj>'2022-01-01' and doj<'2022-07-01' and
d_id=4;
Empty set (0.00 sec)
mysql> select * from employee where doj>'2022-01-01' and doj<'2022-07-01' and
e_id=4;
+------+--------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+--------+----------+------------+------+------+------------+--------+
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 25000 |
+------+--------+----------+------------+------+------+------------+--------+
1 row in set (0.00 sec)
mysql> select * from employee where doj>'2022-05-05';
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
1 row in set (0.00 sec)
mysql> selecgt * from employee where salary> 20000 and e_id>4;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'selecgt
* from employee where salary> 20000 and e_id>4' at line 1
mysql> select * from employee where salary> 20000 and e_id>4;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 25000 |
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
2 rows in set (0.00 sec)
mysql> desc project;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| p_id | int | NO | PRI | NULL | |
| p_name | varchar(30) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select * from project;
+------+---------+
| p_id | p_name |
+------+---------+
| 4220 | Ajay |
+------+---------+
1 row in set (0.05 sec)
mysql> select * from employee;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 25000 |
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 25000 |
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
4 rows in set (0.00 sec)
mysql> select * from employee where adress like 'pune';
ERROR 1054 (42S22): Unknown column 'adress' in 'where clause'
mysql> select * from employee where address like 'pune';
+------+---------+---------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+---------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
+------+---------+---------+------------+------+------+------------+--------+
1 row in set (0.04 sec)
mysql> select * from employee where e_name like '%y';
+------+--------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+--------+----------+------------+------+------+------------+--------+
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 25000 |
+------+--------+----------+------------+------+------+------------+--------+
1 row in set (0.00 sec)
mysql> select * from employee where e_name like 'a%';
+------+--------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+--------+----------+------------+------+------+------------+--------+
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 25000 |
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 25000 |
+------+--------+----------+------------+------+------+------------+--------+
2 rows in set (0.00 sec)
mysql> select * from employee where e_name like '_______';
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
2 rows in set (0.00 sec)
mysql> select * from employee where e_nmae like '__v%';
ERROR 1054 (42S22): Unknown column 'e_nmae' in 'where clause'
mysql> select * from employee where e_name like '__v%';
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 25000 |
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
2 rows in set (0.00 sec)
mysql> select * from employee where address not like 'pune';
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 25000 |
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 25000 |
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
3 rows in set (0.00 sec)
mysql> select sum(salary) from employee;
+-------------+
| sum(salary) |
+-------------+
| 100000 |
+-------------+
1 row in set (0.04 sec)
mysql> select count(d_id) from employee where p_id='4220';
+-------------+
| count(d_id) |
+-------------+
| 4 |
+-------------+
1 row in set (0.04 sec)
mysql> select salary from employee where salary = some (select e.salary from
employee as e where e.e_id=5);
+--------+
| salary |
+--------+
| 25000 |
| 25000 |
| 25000 |
| 25000 |
+--------+
4 rows in set (0.04 sec)
mysql> update employee
-> set salary =23000;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> update employee
-> set salary =25000
-> where e_id=7;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update employee
-> set salary =27000
-> where e_id=4;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update employee
-> set salary = 30000
-> where e_id=5;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from employee;
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 1 | Ajay | pune | 2021-09-25 | 4000 | 4220 | NULL | 23000 |
| 4 | Arvind | AIT PUNE | 2022-04-03 | 4000 | 4220 | 124124 | 27000 |
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 30000 |
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
4 rows in set (0.00 sec)
mysql> select * from employee where salary >=all( select salary from employee);
+------+--------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+--------+----------+------------+------+------+------------+--------+
| 5 | Abhay | AIT PUNE | 2022-02-01 | 4000 | 4220 | 1235124 | 30000 |
+------+--------+----------+------------+------+------+------------+--------+
1 row in set (0.04 sec)
mysql> select * from employee where salary =some( select e.salary from employee as
e where e.e_id=7);
+------+---------+----------+------------+------+------+------------+--------+
| e_id | e_name | address | doj | d_id | p_id | contact_no | salary |
+------+---------+----------+------------+------+------+------------+--------+
| 7 | Shivank | AIT PUNE | 2022-06-08 | 4000 | 4220 | 12828324 | 25000 |
+------+---------+----------+------------+------+------+------------+--------+
1 row in set (0.00 sec)
mysql> select * from employee natural join department;
+------+------+---------+----------+------------+------+------------+--------
+--------+----------------------+
| d_id | e_id | e_name | address | doj | p_id | contact_no | salary |
d_name | location |
+------+------+---------+----------+------------+------+------------+--------
+--------+----------------------+
| 4000 | 1 | Ajay | pune | 2021-09-25 | 4220 | NULL | 23000 | IT
| ACAD BLOCK, AIT PUNE |
| 4000 | 4 | Arvind | AIT PUNE | 2022-04-03 | 4220 | 124124 | 27000 | IT
| ACAD BLOCK, AIT PUNE |
| 4000 | 5 | Abhay | AIT PUNE | 2022-02-01 | 4220 | 1235124 | 30000 | IT
| ACAD BLOCK, AIT PUNE |
| 4000 | 7 | Shivank | AIT PUNE | 2022-06-08 | 4220 | 12828324 | 25000 | IT
| ACAD BLOCK, AIT PUNE |
+------+------+---------+----------+------------+------+------------+--------
+--------+----------------------+
4 rows in set (0.05 sec)