DBMS Assignment
DBMS Assignment
– 1
Emp_name Varchar2 20
Dept_id Number 20
1 Alice 10
2 Bob 20
3 Charlie 30
4 David NULL
5 Emma 10
6 Frank 20
7 Grace 30
8 Hannah 30
Q3. Create the following table “Departments”
Dept_name Varchar2 10
Dept_id Dept_name
10 HR
20 IT
40 Marketing
30 Finance
50 Operations
60 Research
70 Legal
80 Sales
OBJECTIVE :
Ans -
Output
Ans -
Output
I). Use an INNER JOIN to find the names of employees who belong to a department.
Ans:
Output
II). Use a LEFT OUTER JOIN to list all employees, showing their department if they have one. If
an employee does not belong to a department, show NULL for the department name.
Ans:
Output
III). Use a RIGHT OUTER JOIN to list all departments, showing the names of employees in each
department. If a department has no employees, show NULL for the employee’s name.
Ans:
Output
IV). Use a FULL OUTER JOIN to list all employees and all departments, showing NULL for
departments with no employees and employees with no department.
Ans:
Output
V). Use an INNER JOIN to find the names of employees who are in both IT and HR departments.
Ans:
Output
VI). Write a query to find employees without a department using a LEFT JOIN.
Ans:
Output
VII). Find the total number of employees in each department using INNER JOIN and
GROUP BY.
Ans:
Output
VIII). Find all employees who do not belong to either the “HR” or “IT” department using an
OUTER JOIN.
Ans:
Output
XI). List the names of employees and departments where employees work, but exclude records
where department names start with the letter "M."
Ans:
Output
X). Use a LEFT JOIN to list all employees and count how many employees are in each department,
even if some departments have no employees.
Ans:
Output
XI). Find the department name and employee name for employees who have no department
assigned by using an OUTER JOIN.
Ans:
Output
XII). Write a query to find employees who are in the same department as another employee.
(This query uses a Self Join to find pairs of employees in the same department.)
Ans:
Output
Assignment – 2
OBJECTIVES:
Output
II). Retrieve the total number of employees.
Ans:
Output
Output
Output
Output
VIII). List all employees who joined after January 1, 2020.
Ans:
Output
IX). Find the department name and total salary paid in that department using LEFT
JOIN.
Ans:
Output
X). Calculate the total salary paid to employees, rounded to two decimal places.
Ans:
Output
Assignment - 3
Q1. Create the following table “Employees_2023”
emp_name VARCHAR2 20
dept_id NUMBER 10
1 Alice 10
2 Bob 20
3 Charlie 30
4 David 40
emp_name VARCHAR2 20
dept_id NUMBER 10
Q4. Insert the following data in the Employees_2024 table
2 Bob 20
3 Charlie 30
5 Eve 50
6 Frank 60
OBJECTIVE:
Q1. Create Table Employees_2023.
Ans:
Output
Output
Output
Output
VII). Find employees who are only in one table but not both.
Ans:
Output
VIII).Find employees whose emp_id is greater than 3 from both tables.
Ans:
Output
IX). Find employees who are in Employees_2023 but not in Employees_2024, and sort them by
dept_id.
Ans:
Output
X). Retrieve all employees from both tables, including duplicates.
Ans:
Output