Skip to content
Snippets Groups Projects
Unverified Commit 7d4987ff authored by Natalie's avatar Natalie Committed by GitHub
Browse files

docs - update sql (#23087)

parent ffc97794
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ What type of [SQL variable][sql-variable-def] are you using?
- [Filter widget doesn't display a dropdown menu of values](./filters.html#are-you-seeing-a-different-kind-of-input-widget-than-you-expected).
- [SQL query contains a subquery (nested query) or CTE](../users-guide/13-sql-parameters.html#field-filters-dont-work-with-table-aliases).
- [400 error from BigQuery](../users-guide/13-sql-parameters.html#some-databases-require-the-schema-in-the-from-clause).
- [SQL syntax error: missing `FROM` clause](../users-guide/writing-sql.html#how-metabase-executes-sql-variables).
### Text, number, or date variables
......
......@@ -56,7 +56,9 @@ When you run a query from the SQL editor, Metabase sends the query to your datab
## How Metabase executes SQL variables
When your query includes a SQL variable, the `{% raw %}{{#5}}{% endraw %}` tag will be substituted with the SQL query of the referenced question or model, surrounded by parentheses.
When you run a query that includes a [variable][variable-gloss], the query will be executed by replacing the `{% raw %}{{ variable_name_or_id }}{% endraw %}` tag with the SQL query of the referenced question or model.
This means that your main query must be aware of all the tables that your variable is pointing to, otherwise you'll get a SQL syntax error. For example, if your main query uses the `Products` table, but your variable points to a query that uses the `Orders` table, you'll need to include a join to `Orders` in your main query.
For an example, see the documentation on [Referencing models and saved questions in SQL queries](../users-guide/referencing-saved-questions-in-queries.html).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment