sql_table_name (for joins)

This page refers to the sql_table_name parameter that is part of a join.

sql_table_name can also be used as part of a view, described on the sql_table_name (for views) parameter documentation page.

sql_table_name can also be used as part of an Explore, described on the sql_table_name (for Explores) parameter documentation page.

Usage

explore: view_name {
  join: view_name {
    sql_table_name: table_name ;;
  }
}
Hierarchy
sql_table_name
Default Value
None

Accepts
A table name in your database

Special Rules

Definition

Typically the view on which a join is based defines the table to be queried.

You can use sql_table_name to set the table in your database to be queried by a join. This is unusual, but it can be useful when multiple tables have the same schema; it allows the same view to be used to describe all of them. sql_table_name lets you specify which tables should be used by the view that you are joining. In such situations, consider using extends or refinements.

Scoping table names

When you reference a table using the table name alone, Looker will use the default search path (the database and schema) that your Looker admin has configured in the settings for the database connection. See the Things to consider section of this page for more information.

If you need to reference a table in a different database and schema that is not in the database user's default search path, you can scope the table name using the <database_name>.<schema_name>.<table_name> format to point to another database or schema:

  • To reference a table from a different schema, use <schema_name>.<table_name>, as shown in the example on this page.
  • To reference a table from a different database, use the full <database_name>.<schema_name>.<table_name>.

For a Google BigQuery connection, you can reference a table in a different project and dataset by scoping the table name using the format <project_name>.<dataset_name>.<table_name>. See the Google BigQuery connection documentation page for additional information.

Examples

This example makes the customers join rely on the customer_1 table from the default schema:

explore: orders {
  join: customers {
    sql_table_name: customer_1 ;;
    sql_on: ${order.customer_id} = ${customer.id} ;;
  }
}

This example makes the customers join rely on the customer_1 table from the analytics schema by scoping the table name to include the schema name (using the format <schema_name>.<table_name>):

explore: orders {
  join: customers {
    sql_table_name: analytics.customer_1 ;;
    sql_on: ${order.customer_id} = ${customer.id} ;;
  }
}

Things to consider

Tables referenced by sql_table_name must be accessible from the current connection

When the sql_table_name parameter is used within a join object, that join object is defined within an explore object, which is in turn included in a model object. (The Hierarchy on this page shows this relationship chain.) The model object has a database connection defined in it. When you reference a database table in the sql_table_name parameter, the table needs to be accessible within the associated connection specified in the model file.

The default database and schema (or, for Google BigQuery, the billing project and dataset) are defined by your Looker admin when they create the Looker connection to your database for the database connection.

To name a join differently than the underlying table, apply sql_table_name at the view level

Using sql_table_name at the join level, as described on this page, is uncommon. It should only be used when the same view can describe multiple tables.

The more typical method is to use sql_table_name at the view level to name a view differently than the underlying table name.

Instead of this:

Model File

explore: orders {
  join: customers {
    sql_table_name: customer_1 ;;
    sql_on: ${order.customer_id} = ${customer.id} ;;
  }
}}

do this:

Model File

explore: orders {
  join: customers {
    sql_on: ${order.customer_id} = ${customer.id} ;;
  }
}

View File

view: customers {
  sql_table_name: customer_1 ;;
}