When creating a query, there may be times when the parameters you need are not available from the query type you want. For example, you may want to generate a list of all Contacts who have given to a specific Project in the last year. If you’ve seen our video on Query Types, you’ll know that you want to create a Contact query. But that doesn’t include the ability to specify Gifts to specific Projects.
Here, we will need to create a nested query. We can create a Gift query to find all Gifts to our Urban Youth project in the last year, and then save that query. Then we can build a Contact query and nest in our saved Gift query, To do this, we’ll select “Contacts” as our parameter, and then specify that we want Contacts in our Gift query.
Nested queries are ideal for triggering Automation actions, since Workflow steps must be tied to either a Contact or Individual query.
In addition to nesting other query types into Contact or Individual queries, it’s also possible to nest a Project query into a Gift query. Use this option to identify Gifts to specific Projects in your system. For example, you could find all Gifts to Projects that are Active, have a Type of Youth Programs, and are located in the Atlantic Region. As before, just save a Project query with the parameters you need, and then create a Gift query. In this case, we’ll use “Projects” for our parameter, and then specify that we want Gifts to Projects that are In our Project query.
Nested queries can be powerful, but remember, with great power comes great responsibility. 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.
Now that you know how to nest queries, you’ll be ready to tackle any data challenge, but all the same, feel free to check out any of our other training videos on this and other topics whenever you need a refresher.