I'm having trouble with SQL. I have created a database of a restaurant and I am trying to create query that shows supervisors and employees who have served the same customer.
The Employee
table has supervisor_id
and employee_id
. The Order
table has the customer_id
and the employee_id
associated with that customer. I know that this involves a subquery and I know it would look something this.
SELECT DISTINCT
Employee.employee_id,
Orders.customer_id,
Employee.supervisor_id
FROM Employee,
Orders
WHERE EXISTS ( SELECT customer_id,
Employee.employee_id
FROM Orders AS cs2,
Employee
WHERE cs2.employee_id = Employee.employee_id
AND Employee.supervisor_id = Employee.employee_id
AND cs2.customer_id = Orders.customer_id );
As of right now, this query is not returning any results.
Could be something like this: