Many-to-Many Joins and Bridge Tables/Join through a bridge table

Resolve many-to-many relationships with two joins.

Section: Many-to-many joins

Join through a bridge table

sql
sql
SELECT u.user_id, u.email, r.role_name
FROM users u
JOIN user_roles ur ON ur.user_id = u.user_id
JOIN roles r ON r.role_id = ur.role_id;
Explanation

The bridge table stores relationship rows and often uses a composite key.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Many-to-many joins
Aggregate across a many-to-many relationship
Count related entities after joining through the bridge.
OpenIn sheetsqlsame section
Find posts with all required tags
Join and group, then compare distinct matched tags to the required count.
OpenIn sheetsqlsame section
Index bridge-table foreign keys
Index both sides of the relationship for join speed.
OpenIn sheetsql1 tag match