Sunday, April 16, 2006

SECTION 3 LESSON 5
1. Display the employee's last name and employee number along with the manager's last name and manager number. Label the columns:Employee, Emp#, Manager, and Mgr#, respectively. -

---select e.last_name "Employee",e.employee_id "Emp #",m.manager_id "Mgr #",m.last_name "Manager"
from employees e,employees m
where e.employee_id=m.manager_id

2. Modify question 1 to display all employees and their managers, even if the employee does not have a manager. Order the list alphabetically by the last name of the employee.

----select e.last_name "Employee",e.employee_id "Emp #",m.manager_id "Mgr #",m.last_name "Manager"
from employees e,employees

where e.employee_id(+)=m.manager_id
order by e.last_name;

3. Display the names and hire dates for all employees who were hired before their managers, along with their managers' names and hire dates. Label the columns Employee, Emp Hired, Manager, and Mgr Hired, respectively
d
---- select e.first_name' 'e.last_name "Employee",e.hire_date "Emp Hire",m.first_name' 'm.last_name "Manager",m.hire_date "Mgr Hire"
from employees e,employees m
where e.manager_id=m.employee_id and e.hire_date

4. Finish this code to produce all possible combinations of rows from both tables:
SELECT e.last_name, e.department_id, d.department_name

----SELECT e.last_name, e.department_id, d.department_name
from employees e,departments d
where e.department_id=d.department_id;

5. Finish this code to produce all information in the departments table whether it has a match in the locations table or not:
SELECT l.location_id, l.city, d.department_name

----SELECT l.location_id, l.city, d.department_name
from locations l,departments d
where l.location_id=d.department_id;

6. Finish this code to produce the following information for Diana Lorentz:
SELECT e.last_name, d.department_name

----select e.last_name,d.department_name
from employees e,departments d
where e.last_name='Diana', e.first_name='Lorentz'
and e.department_id=d.department_id;

7. How do you know which side of a join gets the (+) sign?
----This side has the values that the other doesn't.

0 Comments:

Post a Comment

<< Home