I have three tables representing a many-many relationship. They are board_name
, topic_name
and board_topic
.
Someone told me how to query these tables to get the results I want, but it currently seems like Voodoo to me. I have done some research on joins, but it is still not clear.
Could someone please explain how the query below works? For example how are the two joins related? Do they represent two sides of the join somehow? Is there a simpler way to write this query?
I have an idea that, like a butterfly, the left-hand side is joined to the center and so is the right-hand side. Maybe a picture could help me to understand?
Any help appreciated.
SELECT board_name, topic_name FROM board
JOIN board_topic ON board.id = board_topic.board_id
JOIN topic ON topic.id = board_topic.topic_id
WHERE topic_name = "differentiation";