SQL Assignment 5
SQL Assignment 5
1. Write a query for the HR department to produce the addresses of all the departments.
Use the LOCATIONS and COUNTRIES tables. Show the location ID, street
address, city, state or province, and country in the output. Use a NATURAL JOIN to
e.country_id=d.country_id;
2. When Cartesian product is formed in Oracle Join and how to avoid it?
Cartesian product or cross join is formed when join condition is omitted or join
condition is invalid .In order to avoid it, we need to include a valid join condition;
4. The HR department needs a report of all employees. Write a query to display the last
e.department_id=d.department_id;
5. The HR department needs a report of employees in Toronto. Display the last name,
job, department number, and department name for all employees who work in
Toronto.
TRUE
7. Create a report to display the last name and employee number of employees along
with their manager’s last name and manager number. Label the columns Employee,
8. What is the need to qualify the names of the columns with the table name in joining?
We needed to qualify the names of columns with table names in order to avoid
ambiguity.
Ex. without table prefixes locaton_id can be from locations or countries creating
ambiguity.
operator (=).
Ex.Salary coloumn in employees table must be between lowest_salary and
10.Create a report for the HR department that displays employee last names, department
numbers, and all the employees who work in the same department as a given employee.
ON (e.department_id = c.department_id)
11. Differentiate between LEFT OUTER JOIN and RIGHT OUTER JOIN.
LEFT OUTER JOIN returns matched rows from joined tables and unmatched rows
from the left table where as RIGHT OUTER JOIN returns matched rows from joined
12. What can be the maximum length of a table alias in table joining?
30 Characters.
13. The NATURAL JOIN and USING clauses are mutually inclusive (TRUE/FALSE).
False.
FUL OUTER JOIN returns matched rows from both the joined tables and unmatched
rows from either table. It combines the results from both LEFT OUTER JOIN and
15. The HR department needs to find the names and hire dates for all employees who were
hired before their managers, along with their managers’ names and hire dates.
select e.first_name ||' '||e.last_name "name",e.hire_date, m.first_name ||' '||m.last_name