0% found this document useful (0 votes)
5 views2 pages

Assignment 5

The document outlines a series of MySQL commands executed on a database named MRINMOY, including the creation of two tables: department2 and employee2. It also includes data insertion into these tables and various SELECT queries to retrieve specific information, such as employees in the Marketing department and the employee with the highest salary. The document demonstrates basic database operations and relationships between tables.

Uploaded by

Mrinmoy Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Assignment 5

The document outlines a series of MySQL commands executed on a database named MRINMOY, including the creation of two tables: department2 and employee2. It also includes data insertion into these tables and various SELECT queries to retrieve specific information, such as employees in the Marketing department and the employee with the highest salary. The document demonstrates basic database operations and relationships between tables.

Uploaded by

Mrinmoy Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

mysql> USE MRINMOY;

Database changed
mysql> show tables;
+-------------------+
| Tables_in_mrinmoy |
+-------------------+
| book |
| department |
| employ |
| employee |
| employee1 |
| employee_details |
| payments |
| student |
+-------------------+
8 rows in set (0.00 sec)

mysql> create table department2 (


-> dept_id int primary key,
-> d_name varchar(20),
-> location varchar(20),
-> doe date);
Query OK, 0 rows affected (0.01 sec)

mysql> create table employee2(


-> emp_no int primary key,
-> name varchar(20),
-> salary decimal(30,2),
-> designation varchar(20),
-> dept_id int,
-> doj date,
-> foreign key (dept_id) references department2(dept_id));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into employee2(emp_no,name,salary,designation,dept_id, doj)


-> values
-> (1,'emp1',50000,'Manager',1,'2023-07-15'),
-> (2,'emp2',45000,'HR',2,'2022-02-10'),
-> (3,'emp3',55000,'Developer',3,'2023-01-20');
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> insert into department2(dept_id, d_name, location, doe)


-> values
-> (1,'Marketing','New York','2020-05-15'),
-> (2,'Sales','San Fran','2019-08-20'),
-> (3,'Engineering','LA','2021-02-10');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from department2;


+---------+-------------+----------+------------+
| dept_id | d_name | location | doe |
+---------+-------------+----------+------------+
| 1 | Marketing | New York | 2020-05-15 |
| 2 | Sales | San Fran | 2019-08-20 |
| 3 | Engineering | LA | 2021-02-10 |
+---------+-------------+----------+------------+
3 rows in set (0.00 sec)

mysql> select * from employee2;


+--------+------+----------+-------------+---------+------------+
| emp_no | name | salary | designation | dept_id | doj |
+--------+------+----------+-------------+---------+------------+
| 1 | emp1 | 50000.00 | Manager | 1 | 2023-07-15 |
| 2 | emp2 | 45000.00 | HR | 2 | 2022-02-10 |
| 3 | emp3 | 55000.00 | Developer | 3 | 2023-01-20 |
+--------+------+----------+-------------+---------+------------+
3 rows in set (0.00 sec)

mysql> select name from employee2 where dept_id=(select dept_id from


department2 where d_name='Marketing');
+------+
| name |
+------+
| emp1 |
+------+
1 row in set (0.00 sec)

mysql> select * from employee2 where month(doj)=7;


+--------+------+----------+-------------+---------+------------+
| emp_no | name | salary | designation | dept_id | doj |
+--------+------+----------+-------------+---------+------------+
| 1 | emp1 | 50000.00 | Manager | 1 | 2023-07-15 |
+--------+------+----------+-------------+---------+------------+
1 row in set (0.00 sec)

mysql> select * from employee2 where salary =(select max(salary) from


employee2);
+--------+------+----------+-------------+---------+------------+
| emp_no | name | salary | designation | dept_id | doj |
+--------+------+----------+-------------+---------+------------+
| 3 | emp3 | 55000.00 | Developer | 3 | 2023-01-20 |
+--------+------+----------+-------------+---------+------------+
1 row in set (0.01 sec)

You might also like