I've been trying to contrust a query to grab columns for 3 tables, but I keep getting mismatched rows.
These are my tables:
- sender (can either be a customerID or employeeID)
- receiver (can either be a customerID or employeeID)
**(Note: for each message it will contain only 1 customer and 1 employee, ie. Customer's dont interact with eachother and employees don't message eachother also)**
For a particular customer with customerID = 5, I want to figure out what is the DepartmentName of the employee they were talking to.
My Intial attemp at this was:
SELECT * FROM Messages,Employee, Departmnet, WHERE sender = '5' OR receiver = '5' AND (Employee.employeeID = Messages.sender OR Employee.employeeID = Messages.Receiver) AND Employee.departmentID = Department.DepartmentID;
However this returns way more rows than expected. I think it's because sender or receiver can potentially be the employeeID.
My 2nd guess is maybe i have to join tables, but i dont have much experience in this. If anyone could show me or tell me how to perform this query I would appreciate it.