Heya, Jgentes.
Now then.
Think about it like this: When you JOIN tables, you're creating one big table out of those multiple tables and searching that, instead of individual tables. That's not exactly how it works under the hood, but it's close enough.
-
SELECT
-
`parts`.`number`,
-
`printers`.`name`
-
FROM
-
(
-
`parts_printer_consumable`
-
AS `ppc`
-
LEFT JOIN
-
`parts`
-
ON
-
`parts`.`part_id` = `ppc`.`consumable_id`
-
LEFT JOIN
-
`printers`
-
ON
-
`printers`.`id` = `ppc`.`printer_id`
-
)
-
WHERE
-
`ppc`.`printer_id` = '19'
-
I changed your JOINs to LEFT JOINs and switched the order so that you will only get results if there are results in the `ppc` table.
Aside from being easier to look at, this setup makes more sense. What you are doing is taking all of the results from `ppc` and appending rows from `parts` where the IDs match up, then appending rows from `printers` where those IDs match up and then filter the whole thing by `printer_id`.
Note that because `ppc` is the origin table for the JOIN, MySQL is smart enough to evaluate the WHERE clause before joining the other tables.
PS, you're looking for [code=mysql].