A table can be joined with itself too. If every row of a category table carries the number of its parent category, then to see a category with its parent's name you put the same table into the query under two different names: one in the role of "child", one of "parent".
SELECT c.name AS category, p.name AS parentFROM categories AS cJOIN categories AS p ON p.id = c.parent_id;
parent_id missing) drop out of the result with a plain JOIN.Many-to-many relations are kept in a linking table: if a book can have several tags and a tag several books, a book_tags table carries one row per pairing. Getting from book to tag takes two JOINs: book → linking table → tag. Build the chain one link at a time.