Here is an theoretical example of a problem. i am making a database schema for a business.
I have a table for person, employee, client, production, sales, accounting, and administration humanResources.
Person:
contact_id (primary key)
first_name
last_name
phone
email
Employee:
employee_id (primary key)
contact_id (foreign key) References Person(contact_id)
date_start
Production:
production_id (primary key)
employee_id (foreign key) References Employee(employee_id)
//other information
Sales:
sales_id (primary key)
employee_id (foreign key) References Employee(employee_id)
//other information
Accounting:
accounting_id (primary key)
employee_id (foreign key) References Employee(employee_id)
//other information
Administration:
administrator_id (primary key)
employee_id (foreign key) References Employee(employee_id)
//other information
HumanResources:
humanResources_id (primary key)
employee_id (foreign key) References Employee(employee_id)
//other information
Client
client_id (primary key)
contact_id (foreign key) References Person(contact_id)
employee_id (foreign key) References Employee(employee_id)
//other information
Client is a bad name for the table. it mainly keeps track on what employee a client was in contact with, and we can assume what the conversation is about depending on the department the employee is working in at that time.
Assuming that an employee may work in more than one department, return the first name and last name of employees that work in at least one of certain two or three of the companies departments.
is it some thing like this:
SELECT b.first_name, b.last_name FROM Employee a
LEFT JOIN Person b USING(contact_id)
INNER JOIN Production c USING(employee_id)
WHERE a.employee_id IN (SELECT contact_id FROM Client)
UNION
SELECT b.first_name, b.last_name FROM Employee a
LEFT JOIN Person b USING(contact_id)
INNER JOIN Accounting c USING(employee_id)
WHERE a.employee_id IN (SELECT contact_id FROM Client)
UNION
SELECT b.first_name, b.last_name FROM Employee a
LEFT JOIN Person b USING(contact_id)
INNER JOIN Sales c USING(employee_id)
WHERE a.employee_id IN (SELECT contact_id FROM Client);