From 2a71742160ef42fe2cfc9addc85bc8f6688c7830 Mon Sep 17 00:00:00 2001 From: ian lyons Date: Wed, 15 Jan 2025 06:15:09 -0500 Subject: [PATCH] docs: Clarify filtering requirements for SQL docs --- contents/docs/product-analytics/sql.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contents/docs/product-analytics/sql.md b/contents/docs/product-analytics/sql.md index 882acc10e3ef..89c2ca704fb9 100644 --- a/contents/docs/product-analytics/sql.md +++ b/contents/docs/product-analytics/sql.md @@ -112,7 +112,7 @@ WHERE event = '$pageview' AND properties.$current_url LIKE '%/blog%' ``` -To have the insight or dashboard date range selector apply to the insight, include `{filters}` in query like this: +To have the insight or dashboard date range selector apply to an insight that includes the `events` or `sessions` tables, include `{filters}` in your query like this: ```sql SELECT * @@ -122,6 +122,15 @@ WHERE event = '$pageview' AND {filters} ``` +Otherwise, if you're querying from tables that aren't `events` or `sessions`, you can use the `{filters.dateRange.from}` and `{filters.dateRange.to}` variables in your query like this: +```sql +SELECT * +FROM your_table yt +WHERE yt.table_column = 'column_name' + AND yt.created_at > {filters.dateRange.from} + AND yt.created_at < {filters.dateRange.to} +``` + `WHERE` is also useful for querying across multiple tables. For example, if you have the Hubspot connector set up, you can get a count of events for contacts with a query like this: ```sql