If the parameters you need are not available in a single query type you want, you may have to create a nested query. This means that output from a different query can be used as a parameter! In other words, you can create a subset of results from another query by creating a nested query.
For example: You may want a list of all contacts that have given to a specific project in the last year.
This will be a list of contacts, so the main query should be a contact query. But that alone will not specify gifts given to specific projects. Therefore, this will include a gift query (with specific project information) nested inside the contact query. Here's how you can make this happen.
First, Create the gift query. Include date and project parameters - so, in this example, we're looking for gifts within the last 365 days that were attributed to Urban Youth.
Second, save the gift query and note the name of the query (in this case, Urban Youth Gifts in Last Year). You'll need that name to insert into the next query!
Now, create the contact query. Remember, you want to pull the list of contacts from the list of gifts in the previous query. So, you're looking for contacts in that query. To do this, indicate the parameter as such - the value will be the name of the query you want to nest into this one (in this case, Urban Youth Gifts in Last Year):
Finally, save and run this query. This will give you the list of contacts from the list of gifts attributed to a specific project!
The caveat: Keep in mind that while you can combine data types via nested queries, the final output of the main query will only contain the available output for that query type. In this example, that means that the final contact query will allow you to export contact-based values, but not gift-based or project-based values. In other words, you can export contact types of those who gave toward Urban Youth, but you cannot export gift types of the gifts they gave.
Use Cases for Nested Contact and Individual Queries
Only the Contact and Individual query types are compatible with automation. The great news is: you can absolutely use a nested query as the base of a step to trigger a set of actions. In the example above, we could use this query to trigger automated outreach to donors who have given toward Urban Youth!
Other Nested Queries
Of course, you are not limited to only having Contact or Individual nested queries. You can mix and match as you'd like using the same approach as above. So, if you wanted to look at gifts that came from active projects of a particular type, you could nest a project query into a gift query. The possibilities are endless, and this is demonstrates the true power of queries!
To Nest, or Not to Nest?
As mentioned earlier, if you have all the fields you need in one query, then you only need one. Nesting queries is best for when this isn't true.
Be careful with how many you nest into one. You could theoretically nest queries into nested queries (query-ception, if you will), but too much of this could give you an error message. So be sure to plan out the information you need and the most efficient way to build out your nested query to accommodate it.
Additionally, if you delete a query that has been nested into another query, you’ll end up getting an error message. So, be sure to limit deleting queries, especially if you are using nested queries to power automated workflows.