Suppose I have a query like this:
SELECT
s.staffID as staffID,
CONCAT_WS(", ", lname, fname) AS name,
GROUP_CONCAT(unit SEPARATOR ", ") AS units
FROM
staff s,
units u,
staff_units r
WHERE
s.staffID = r.staffID
AND u.unitID = r.unitID
GROUP BY s.staffID
ORDER BY lname
This gets a list something like this:
Alice Accounting
Bob Systems
Charlie Customer Services, Administration
Okay so far. Now suppose that I delete the entry in staff_units
that records Alice as a member of Accounting. Running this query will then yield a list from which Alice is excluded even though she still exists in the staff
table:
Bob Systems
Charlie Customer Services, Administration
Can I adjust this SQL so that it continues to return Alice as a result, showing her as unassigned to a unit?
I could of course run one query to get a list of staff, and another query for each one of them to get current assignments. But that would mean running n+1 queries to build the list, where n is the number of staff, and that just rubs me wrong.