Skip to main content
Filters a query using the results of another query. Returns only the rows that are included in the other query’s results. In SQL, this generates a WHERE clause that looks like WHERE IN (SELECT... where the SELECT clause is the filtering query.
To exclude data using the results of another query, use field_name_not_in_query.

Requirements

Only supported for use in query views. Refer to the Examples section for the complete syntax.

Syntax

Properties

field_name
string
required
The field to filter on, specified in the format view_name.field_name. Can be a time, numeric, or string field.
field_name_in_query
string
required
The name of the field in the filtering query, specified in the format view_name.field_name. This field must contain the same data and be the same data type as the field_name.For example, if you filter on a customers.country field, the value of filtering_field_name should contain a field with country data.

Examples

Click the SQL tab in a code block to view the query’s underlying SQL definition.
The first query in this example - shown below - lists the top 5 countries with the highest number of customer sign ups:
The second query applies a filter that uses the results of Query 1. This means that the results should only include the countries that are present in the results of the first query.
The underlying YAML for a query view created from Query 2 would look like the following:
Query view filtered using the results of another query