Outerbase SDK
  • Outerbase SDK
  • Get Started
    • Overview
    • Playground
  • Introspection
    • Overview
    • Universal data language
    • Connect a data source
    • Generate models
      • Limit table scope
    • Remote queries
  • Query Builder
    • Overview
    • Select
      • Single table
      • Multiple tables
      • Where clauses
      • Join tables
      • Limit & Offset
      • Order By
    • Insert
    • Update
    • Delete
    • Returning
    • Operators
    • .toString()
    • .asClass()
    • .query()
    • .queryRaw()
  • Data Sources
    • Overview
    • Outerbase
    • Cloudflare D1
    • Neon
Powered by GitBook
On this page
  1. Query Builder
  2. Select

Join tables

JOIN statements in SQL are used to combine rows from two or more tables based on a related column between them. They allow you to retrieve data that is spread across multiple tables, providing a way to create a comprehensive dataset.

There are different types of JOINs, including INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN, each serving different purposes for how they handle matching and non-matching rows from the involved tables.

To run a JOIN query on your table you can format it by pulling from multiple tables and joining between a column on each of them.

const { data, error } = db
    .selectFrom([
        { table: 'table_1', columns: ['id'] },
        { table: 'table_2', columns: ['column_a'] }
    ])
    .leftJoin('table_1', equalsColumn('table_2.column_a', 'table_1.id'))
    .query()

PreviousWhere clausesNextLimit & Offset

Last updated 11 months ago