Skip to main content

Subquery search (in keyword)

Use keywords to preform subquery searches

Written by Tyler Kraeger
Updated this week

You can use the IN keyword to perform a nested search. This keyword allows you to conduct a search on top of another search, commonly known as a subquery, without needing to create a separate view.

Suppose you need to narrow a result based on specific criteria defined by another search. For example, imagine you want to find the top 3 campuses by total donation volume, and then you want to see all donations across all Funds for those 3 Campuses.

You can accomplish this entire analysis in a single search using the in keyword. This allows you to benefit from dynamic calculations without the extra steps of building and joining views.

The "in" keyword

Searches using the in keyword do not include {null} values. To include these values, create a formula for the relevant attribute in your search to convert {null} values to a string like 'unknown' or a similar placeholder.

"in"

This performs a query-in-query search, essentially the intersection of two sets. You must match the last attribute before the keyword with the first attribute inside the subsearch. The first attribute in the sub-string must be the same as the attribute immediately preceding the in keyword.

Syntax

attribute in (attribute subsearch)

Examples

Campus Name in (top 3 Campus Name by Total amount)
Fund Name in (top 3 Fund Name by Total amount)

"not in"

This performs the relative complement of two sets. Like the standard in keyword, the last attribute before the keyword must match the first attribute inside the subsearch.

Please note that this keyword does not support the use of the vs keyword.

Syntax

attribute not in (attribute subsearch)

Example

donor 2025 donor not in (donor Transaction Date 2024)

This example Finds individuals who donated in 2025 that did not donate in 2024.

Creating an IN search example

Let's assume you would like to find which three campuses collected the most donations. You would also like to see the fund breakdown for each of the campuses listed.

  1. Start a new Chart Builder session.

  2. Run the search you plan to use for the in clause. This serves as your first-level search. Ensure the result is exactly what you are looking for. In this case:

    1. Total Amount  Campus Name  Fund Name
  3. Now add the in clause to the original search. In this case:

    1. Total Amount Campus Name  Fund Name  Campus name in (top 3 Campus Name by Total Amount)

Step two and three can be combined into one action. They are split into two steps to help simplify the example.

Creating multiple IN searches in a single search example

You can add multiple IN searches within a single search. Let's build off of the previous search and narrow down the list of funds.

Let's assume you would like to find which three campuses collected the most donations. You would also like to see the top three funds for each of the campuses listed.

  1. Start a new Chart Builder session.

  2. Run the search you plan to use for the in clause. This serves as your first-level search. Ensure the result is exactly what you are looking for. In this case:

    1. Total Amount  Campus Name  Fund Name
  3. Now add the in clause to the original search. In this case:

    1. Total Amount Campus Name  Fund Name  Campus name in (top 3 Campus Name by Total Amount)  Fund Name in (top 3 Fund Name by Total Amount

Step two and three can be combined into one action. They are split into two steps to help simplify the example.

Did this answer your question?