Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Clarify filtering requirements for SQL docs #10352

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion contents/docs/product-analytics/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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
Expand Down