Here is the teachers request with his following query as the answer:
[“Q12. Display all employees working for departments 10 and 60.”
mysql> select last_name, department_id
> from employees
> where department_id = 10 or department_id = 60;]
This is the result:
+-----------+---------------+
| last_name | department_id |
+-----------+---------------+
| Hunold | 60 |
| Ernst | 60 |
| Lorentz | 60 |
| Whalen | 10 |
+-----------+---------------+
In my opinion, a better question considering the information a person would want to display would be this: “Display all the employees working for departments 10 and display all of the employees working for department 60.” Under the questions current construction, it seems that he is asking to display only the employees who work for both departments, ie, employees who work for both 60 and 10 at the same time (or at least at different times during the day).
Here’s the table desc:
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| Employee_id | decimal(6,0) | NO | PRI | NULL | |
| First_Name | varchar(20) | YES | | NULL | |
| Last_Name | varchar(25) | NO | | NULL | |
| Email | varchar(20) | YES | | NULL | |
| Phone_Number | varchar(20) | YES | | NULL | |
| Hire_Date | date | NO | | NULL | |
| Job_Id | varchar(10) | YES | | NULL | |
| Salary | decimal(8,2) | YES | | NULL | |
| Commission_Pct | decimal(2,2) | YES | | NULL | |
| Manager_Id | decimal(6,0) | YES | | NULL | |
| Department_Id | decimal(4,0) | YES | | NULL | |
+----------------+--------------+------+-----+---------+-------+
Maybe I’m missing something here. Thanks for any help.
Except, an employee can’t work in two departments with the given table structure (assuming it’s normalized).
Have you tried: