--- title: "Subquery Exports & Outputs" slug: "subquery-exports-outputs" status: "new" updated: 2026-07-21T20:54:23Z published: 2026-07-21T20:54:23Z canonical: "knowledge.technolutions.net/subquery-exports-outputs" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://knowledge.technolutions.net/llms.txt > Use this file to discover all available pages before exploring further. # Subquery Exports & Outputs A subquery is an inner, nested query within an enclosing query. A **subquery export**—as opposed to a subquery filter or a subquery join—is a type of subquery that returns export data.  Like regular exports, subquery exports let you define a *column expression*. What sets them apart from regular exports is their ability to return different kinds of output. These outputs include: - **Rank:** Return a given rank for data with multiple entries, like email addresses. - **Coalesce:** Return only one of two or more possible exports. - **Concatenate:** Combine multiple exports. - **Aggregate:** Perform arithmetic operations on exports and output the result. - **Dictionary:** Return a formatted array available for Liquid looping. - **Existence:** Return a certain output when existence conditions for some data are fulfilled. - **Split:** Splits a string into rows of substrings, based on a specified separator character. - **Formula:** Use SQL to perform operations on exported values. - **XML:** Converts data to XML for use in integrations. - **JSON:** Converts data to JSON for use in integrations. Subquery exports vastly expand your query toolbelt. They can prove useful for formatting data just the way you want it. > [!NOTE] > ✨ Stuck? Ask Slate AI for help! > > [Slate AI](/v1/docs/prompting-slate-ai#prompting-for-querybuilding-help) can help you decide the right output type and help you configure it to return the data you need. > [!TIP] > ⭐ Get Inspired > > This article was adapted in part from [a post by Technolutions staff](https://community.technolutions.net/get-inspired/post/rows-ranks-and-distributions-in-query-results-hBRBidD74DDQCc8) in the Slate Community Forums' Get Inspired space. Have a great idea for a Get Inspired post? [Let us know](https://community.technolutions.net/get-inspired/new?post_type=gnHx7As1gZ8r6Ld)! ## Example: Creating a subquery export A common use case for subquery exports is stitching together multiple exports in a single column. Let’s say you want a single column in your query to return a student’s first and last names, their rank-1 high school, and that high school’s CEEB code. We’ll start by making a Quick Query using Configurable Joins on the person base.  In a query, select the **subquery** icon next to Export to create a subquery export.  In the Edit Part menu, you can get to other data, like the student’s high school, by adding a join to another base. Here, we’ll join to *School by Level of Study, Rank*.  The join exists only in this subquery. If you instead want that school data to be accessible to every other query part, you can create a join at the base level. For more information, see [Joins](/v1/docs/joins). We select the output type, in this case **Concatenate.**  Next, we’ll pick out the data we want to return: namely, first name, last name, school name, and school code. We do so by selecting **Export**, just as we’d do when building a regular query. We can style these exports with literals, or set them apart with a standard character, like a comma, in the **Export Separator** field.  When we save the subquery export, we can preview our results and see a single column of data that contains four exports worth of information. .png) Your particular situation may call for other kinds of output. Keep reading to see what else subquery exports are capable of. ## Subquery copy/paste Use `ctrl/cmd + c` to copy an existing subquery export. Paste into a new subquery export with `ctrl/cmd + v`.  > [!NOTE] > **💡** Check your [browser's clipboard settings](chrome://settings/content/clipboard) if you find you can’t copy/paste subqueries. ## Subquery counts & preview results A count of **Matching Rows** shows the number of records returned by the subquery. Select **Preview Results** in a subquery to see a representative list of results.  #### Subquery check logic Select the **Check Logic cogwheel** .png) and enter the name of a record to see whether it meets your filter criteria. .png) ## Row Limit Some output types include a Row Limit option. This setting controls how many rows are returned from a joined table in the subquery export. For example, joining to Addresses may return multiple rows per record — one for each address. To return only one address, set the Row Limit to 1. ## Rank The **rank** subquery export output pulls one row from a related table. A *sort* dictates the row that is pulled. > [!WARNING] > 📝 **Note:** Some tables do not calculate table ranks and as a result need to be manually sorted. See *Ranking Exclusions* headings in [Database Structure & Determination of Table Ranks](/v1/docs/database-structure-determination-of-table-ranks). Some Slate tables store data such that multiple rows or records may be related to the same record in another table. For example, the School, Address, and Decision tables. These tables are on the *many* end of the [one-to-many relationship](/docs/joins#relationships-between-tables). These tables calculate and store a **rank value**. When such tables need to be joined in queries, and only one row out of many possible rows is needed, this rank value specifies which row should be used in the join. While there are system-wide standard methods to determine the ranking for a particular table, the Rank output in a Subquery allows values to be returned based on a desired custom ranking. #### Example: Return school based on most recent date for conferred degree Say a student received a Bachelors’ Degree from one institution, and later took a course at another institution. The **latter institution ranks higher overall** than the degree-granting institution. This happens because schools are table-ranked by default based on certain attributes, like *Priority*, or *Dates Attended*. An export or join specifying *Rank 1 School* may, in this example, return a mixed set, where some rank 1 schools conferred a degree and others did not. So, how do we specify what we actually mean when we say a school is “rank 1”: that it is the student’s *most recent degree-conferring school*? We can do this with the *rank* subquery export output: 1. In a person-scoped query, select **Subquery Export.** 2. Enter a **name** for the subquery export, like “Rank 1 School”. 3. From the Output list, select **Rank** (selected by default). 4. Under Filters, select **Join**. 5. Select **Schools**. 6. Select **Continue**. This join returns all schools attended. 7. Select **Export**. 8. Under Schools, select **Name**. 9. Select **Continue.** 10. Select **Sort.** 11. Select the direct export by which the schools should be custom-ranked. In this example, we want to rank the schools by the date a degree was conferred. So, select **Conferred Date**. 12. Select **Continue**. 13. Select **Edit** (or double-click) on the sort value. 14. To order the schools from the most recent conferred date, select **Descending** from the Sort Order list. 15. Select **Save.** 16. Click **Save** to save the subquery export.  In the following example, display values from **School Rank 1** (blue) and **School Rank 2** (red) use the standard *School* table ranking. [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360038657072.png) This person attended a school after a degree was granted earlier by a different institution, but because the original rank 1 school has no conferred date, the column **Rank 1 School (by conferred date)** (green) returns data from the degree-granting institution instead. --- ## Coalesce The **coalesce** subquery export output returns the first non-`null` value of at least two potential exports. If more than one value among the potential exports are non-`null`, Slate decides which value to pull by the order you place them in. #### Example: Pull either TOEFL or IELTS scores, but prefer TOEFL if both are present Say your school’s preferred English Proficiency Test is TOEFL, but you’ll accept IELTS if no TOEFL score exists. You can use a coalesce subquery export to choose only the TOEFL score if both are present, and to fall back to an IELTS score if that’s all that’s available. To do this: 1. In a person-scoped query, select **Subquery Export.** 2. Enter a **name** for the subquery export, like “ELP Score Coalesced”. 3. From the Output list, select **Coalesce.** 4. Select **Subquery Export**. 5. Configure the following settings: - **Name:** “TOEFL Total” - **Output:** Rank - **Joins:** Select **Tests -** **TOEFL - Internet-based Test (iBT).** - **Exports:** Under TOEFL - Internet-based Test (iBT), select **Total.**  6. Select **Save.** 7. Select **Subquery Export**. 8. Configure the following settings: - **Name:** “IELTS Total” - **Output:** Rank - **Joins:** Select **Tests - IELTS.** - **Exports:** Under Tests - IELTS, select **IELTS Overall Band Score.**  9. Select **Save.** 10. Click **Save** to save the subquery export When you preview results (in this case, filtered to just records with IELTS or TOEFL scores for illustrative purposes), we see that the coalesce output has chosen TOEFL scores where present, IELTS scores when absent:  --- ## Concatenate The **concatenate** subquery export output joins multiple values together in one expression. To configure a subquery to concatenate multiple values, make sure that the necessary joins are included within the subquery part. These joins are not configured on the main query. You can style your concatenate output using the following settings: - Row Limit - Row Separator - Row Offset - Export Separator - Literal #### Example: Custom Label with Name and School Information 1. Click or drag Subquery into the Exports section. Give the subquery part a Name. 2. In the Edit Part window, select **Concatenate** for Output. 3. In the Add Filter section, click **Join**. To use school data in the concatenation, select one of the School joins. In the following example, we use School by Level of Study, Rank, with the following configuration: - **Name:** Rank 1 High School - **Level of Study:** High School - **Rank:** 1 4. We can now add School exports that return values for the Rank 1 High School. Since the main query uses a Person base, Person exports are already directly available in the subquery part. 5. To define the concatenation, we can drag the exports into the desired order and insert literals for any other characters or strings as needed: [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360039321252.png) 6. Click **Save**. The *Custom Label* column now displays concatenated values: | Reference ID | First | Last | Custom Label | | --- | --- | --- | --- | | 133472569 | Alexander | Hamilton | Alexander Hamilton: New Trier Township High School (144430) | #### Example: Return a comma-separated list of schools attended 1. In the Edit Part window, select **Concatenate** for Output. 2. In the **Add Filter** section, click **Join**. 3. Select **Schools** to look across the many possible related rows. The join name may be customized if desired. 4. To return values for school names, add an export within the subquery. Select the *Name* export from the School direct exports. 5. In **Row Separator**, enter: **,** (make sure to enter a space to add spaces between the comma separated values) 6. Click **Save**. [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360039323892.png) The column now returns a comma separated list of school names, if there is more than one school attended. **Sample Output:** `Richard Milburn Academy - West, Cypress Charter High School` --- ## Aggregate The Aggregate output returns values based on a specified function: - Count - Count Distinct - Average - Median - Minimum - Maximum - Sum - Standard Deviation - Variance In the Edit window of a new subquery part, select **Aggregate** as the Output. Within the subquery, the joins with the multiple icon are used. “Multiple” indicates that more than one record can be returned by this join (i.e. a one-to-many relationship). This is required in the Aggregate subquery as multiple records are aggregated or grouped in this part to return a single value. #### Example: Count of number of schools on the student record 1. On the **Aggregate** dropdown in the subquery part, select **Count**. 2. Click **Join** to add School data for the subquery, and select **Schools**. The join can be renamed if desired. [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360039316231.png) 3. Click **Save**. It is not necessary to add exports within the subquery. In this example, the *No. of Schools* column returns a count of how many schools there are on each student record. | Person Person Reference ID | Person First | Person Last | No. of Schools | | --- | --- | --- | --- | | 133472569 | Aprilette | Gammill | 1 | | 658423589 | Gene | Farraway | 1 | --- ## Ranking Use the **Ranking** subquery export output to assign a row number, rank, dense rank, or distribution bucket to rows returned by a subquery. Ranking values are based on the sort you define in the subquery export. Ranking outputs can help identify top donors, top event attendees, leaderboard positions, and segmented groups based on values such as lifetime giving, fiscal year giving, or event registration counts. #### Ranking functions | Function | Description | Example | | --- | --- | --- | | **Row Number** | Returns the row number for each record based on the selected sort. | If results are sorted by lifetime giving, the top donor returns `1`, the next donor returns `2`, and the sequence continues. | | **Rank** | Assigns a ranking based on the sort order. If records tie, the next rank skips the tied positions. | `1, 2, 3, 3, 5` | | **Dense Rank** | Assigns a ranking based on the sort order. If records tie, the next rank continues with the next number. | `1, 2, 3, 3, 4` | | **Distribution** | Segments results into equal groups, such as quartiles or deciles, based on the selected sort and interval. | An interval of `4` divides results into quartiles. An interval of `10` divides results into deciles. | > [!WARNING] > Note > > Ranking depends on the sort order in the subquery export. Confirm the selected sort before using ranking values for reporting, segmentation, or automation. #### Try a Slate example Copy this [Suitcase](/docs/suitcase-import) ID and paste it in **Database → Suitcase Import** to import a pre-made example query: ```SuitcaseID 9725b079-59bd-4bda-94ac-36a520bdc6ac:slate-advancement-showcase ``` #### Configuring a ranking output 1. In a query, add a **Subquery Export**. 2. From the **Output** list, select **Ranking**. 3. From the **Function** list, select **Row Number**, **Rank**, **Dense Rank**, or **Distribution**. 4. Add the exports and joins that define the rows to rank. 5. Add the sort that determines the ranking order. 6. If you select **Distribution**, enter an interval. For example, enter `4` for quartiles or `10` for deciles. 7. Select **Save**. The following example configures a **Dense Rank** function.  The **Distribution** function uses the interval to assign each row to a segment. In this example, the output creates percentile-style groups based on the selected sort.  When records have the same lifetime giving value, **Rank** and **Dense Rank** both assign the same value to tied rows. **Rank** then skips the next position, while **Dense Rank** continues with the next number.  --- ## Dictionary Dictionary output is used with Liquid Markup (for example, in Deliver mailings, with Liquid looping, or with portals, etc). 📖 [The For Tag and Liquid Looping](/v1/docs/liquid-markup-looping) #### Example: Merge a list of missing application requirements in a mailing 1. In the Deliver mailing’s Application-based recipient list query, add a new subquery part. 2. Give the part a **Name**. It is recommended to use a concise, computer-friendly name as it will be referenced as a merge field when creating the contents of the message. 3. Select **Dictionary** in the Output dropdown. 4. To add checklist data, click **Join**. Select **Checklists**, which will return all checklist items per application in the same column. 5. In **Add Export**, add checklist exports that display the desired information that should be conveyed to applicants (e.g. *Subject* displays the name of the checklist item). Similar to the subquery name, the exports should be renamed to be computer friendly so they can be referenced later when creating the message. 6. Add a new **Filter**. A Status filter should be available under Checklist direct filters. This allows the subquery values to return only information on missing items. [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360039325172.png) 7. Use **Add Sort** to sort the data returned based on the selected subquery exports. [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360039318391.png) 8. Click **Save**. When previewing the results of the query, the subquery column returns values in nested PKV tags. [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360038637751.png) In the **Edit Message** section of the Deliver mailing, the subquery part is now available as a merge field. The merge field can be additionally formatted as desired. [](https://cdn.us.document360.io/cd8ea7a6-07f3-4846-a554-627ac016d3e3/Images/Documentation/360038637691.png) #### Nesting dictionary exports You can create a dictionary subquery export inside another dictionary subquery export—in fact, you can go to as many layers of depth as you need. Say you want to see a list of applications, and, for each application, you want to see its associated decision codes. You can do this by: 1. Creating a dictionary subquery that joins to *Applications*. 2. This dictionary subquery export has two exports of its own: a GUID and another dictionary subquery export. 3. The nested dictionary subquery export joins to *Decisions* and returns an export for decision codes.  Nested dictionary exports In a mailing or portal, you can access each of these layers with nested Liquid `for` loops: ```xml
{% for app in apps %}