Skip to main content
Drizzle ORM provides a comprehensive set of join operations to combine data from multiple tables with full type safety.

Inner Join

Retrieve rows that have matching values in both tables:
Inner joins only return rows where the join condition is met in both tables. Users without posts won’t appear in the results.

Left Join

Retrieve all rows from the left table, with matched rows from the right table:
Left joins return all rows from the left table. If no match is found in the right table, the right side fields will be null.

Right Join

Retrieve all rows from the right table, with matched rows from the left table:

Full Join

Retrieve all rows from both tables:
Full join is PostgreSQL-specific. It’s not available in MySQL or SQLite.

Cross Join

Create a Cartesian product of two tables:

Multiple Joins

Join more than two tables:

Join with Partial Select

Select specific columns from joined tables:

Filtering Joined Data

Apply where conditions to joined tables:

Complex Join Conditions

Use multiple conditions in join clauses:

Self Joins

Join a table to itself:

Lateral Joins (PostgreSQL)

Use lateral joins for correlated subqueries:

Join with Aggregations

Combine joins with aggregate functions:

Join with Subqueries

Join to subquery results:

Many-to-Many Joins

Join through a junction table:

Join Types Comparison

Inner Join

Returns only matching rows from both tables. Use when you need data that exists in both tables.

Left Join

Returns all rows from left table, matched rows from right. Use to include all primary records.

Right Join

Returns all rows from right table, matched rows from left. Less common, often swapped for left join.

Full Join

Returns all rows from both tables. Use when you need complete data from both sides.

Cross Join

Cartesian product of both tables. Use for combinations or mathematical operations.

Type Safety with Joins

Drizzle provides full type safety for joined queries:

Performance Tips

1

Index Join Columns

Ensure foreign key columns used in joins are indexed for optimal performance.
2

Select Only Needed Columns

Use partial selects to reduce data transfer when joining large tables.
3

Filter Early

Apply WHERE conditions to reduce rows before joining when possible.
4

Avoid N+1 Queries

Use joins instead of multiple separate queries to fetch related data.

Common Join Patterns

Next Steps

Aggregations

Learn about aggregate functions with joins

Subqueries

Use subqueries in your joins

Select Queries

Master the select query builder

Performance

Optimize your join queries