Inner Join
Simple Inner Join
Simple inner joins can be done by providing a table name and two columns to join:Aliased Inner Join
You can give an alias for the joined table:Complex Join Conditions
You can provide a function as the second argument to get a join builder for creating more complex joins:Subquery Join
You can join a subquery by providing a callback:Left Join
Left join works exactly like inner join but adds aLEFT JOIN instead:
Right Join
Right join works exactly like inner join but adds aRIGHT JOIN instead:
Full Join
Full join is supported by PostgreSQL, MS SQL Server, and SQLite:Cross Join
Cross join produces a Cartesian product of rows:Lateral Join
Lateral joins allow subqueries to reference columns from preceding tables:leftJoinLateral:
Join Builder Methods
The join builder (the callback function in complex joins) has the following methods:on
Add a condition to the ON clause:onRef
Compare two columns in the ON clause:onTrue
Addon true (useful for lateral joins):
Joins in Update Queries
PostgreSQL: From Clause
MySQL: Direct Joins
PostgreSQL: Using Join Methods
Joins in Delete Queries
API Reference
Join Methods
innerJoin(table, column1, column2)- Simple inner joininnerJoin(table, callback)- Inner join with complex conditionsleftJoin(table, column1, column2)- Simple left joinleftJoin(table, callback)- Left join with complex conditionsrightJoin(table, column1, column2)- Simple right joinrightJoin(table, callback)- Right join with complex conditionsfullJoin(table, column1, column2)- Simple full joinfullJoin(table, callback)- Full join with complex conditionscrossJoin(table)- Cross joininnerJoinLateral(callback, joinCallback)- Lateral inner joinleftJoinLateral(callback, joinCallback)- Lateral left join
Join Builder Methods
on(column, operator, value)- Add ON conditiononRef(column1, operator, column2)- Compare two columnsonTrue()- Add ON true