SQLassignment[1]
SQLassignment[1]
Emp_name Varchar2 20
Dept_id Number 20
Query:-
Query:-
Dept_name Varchar2 10
Query:-
Query:-
Query:-
Query:-
Select Emp_name, Dept_name
From Employees left outer join Departments on Employees.Dept_id
= Departments.Dept_id;
Query:-
Use a FULL OUTER JOIN to list all employees and all departments,
showing NULL for departments with no employees and employees
with no department.
Query:-
SELECT Employees.Emp_name, Departments.Dept_name
FROM Employees
LEFT JOIN Departments ON Employees.Dept_id = Departments.Dept_id
UNION
SELECT Employees.Emp_name, Departments.Dept_name
FROM Departments
RIGHT JOIN Employees ON Employees.Dept_id = Departments.Dept_id;
Use an INNER JOIN to find the names of employees who are in both
IT and HR departments.
Query:-
Query:-
Query:-
SELECT Departments.Dept_name,
COUNT(Employees.Emp_id) AS Total_Employees
FROM Employees INNER JOIN Departments ON
Employees.Dept_id = Departments.Dept_id
GROUP BY Departments.Dept_name;
Find all employees who do not belong to either the "HR" or "IT"
department using an OUTER JOIN.
Query:-
Query:-
SELECT e.Emp_name, d.Dept_name
FROM Employees e JOIN
Departments d ON
e.Dept_id = d.Dept_id
WHERE Dept_name NOT LIKE 'M%';
Use a LEFT JOIN to list all employees and count how many
employees are in each department, even if some departments have
no employees.
Query:-
GROUP BY d.Dept_name;
Find the department name and employee name for employees who
have no department assigned by using an OUTER JOIN.
Query:-
SELECT e.Emp_name, d.Dept_name
FROM Employees e LEFT JOIN Departments d
ON e.Dept_id = d.Dept_id
WHERE d.Dept_id IS NULL;
Query:-