<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to show full query results in a SQL alert's notification? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-show-full-query-results-in-a-sql-alert-s-notification/m-p/166318#M55555</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I have a SQL alert; the code behind it looks like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;SELECT COLUMN_1, COLUMN_2, COUNT(*) AS TOTAL, 1 AS FORCE_TRIGGER&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;FROM MY_TABLE&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;GROUP BY COLUMN_1, COLUMN_2&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The idea is that a scheduled job updates my_table and then runs the alert. The alert triggers when MIN(FORCE_TRIGGER) &amp;gt; 0 (in other words, each time it runs). It then sends me a notification via email with the query results included via the variable @QUERY_RESULT_TABLE.&lt;/P&gt;&lt;P&gt;The alert runs successfully and sends me an email. However, in it I only get a single row of query results.&lt;/P&gt;&lt;P&gt;Does anyone know how to get the full query results to display in the email please?&lt;/P&gt;</description>
    <pubDate>Mon, 24 Aug 2026 14:25:34 GMT</pubDate>
    <dc:creator>SRJDB</dc:creator>
    <dc:date>2026-08-24T14:25:34Z</dc:date>
    <item>
      <title>How to show full query results in a SQL alert's notification?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-show-full-query-results-in-a-sql-alert-s-notification/m-p/166318#M55555</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a SQL alert; the code behind it looks like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;SELECT COLUMN_1, COLUMN_2, COUNT(*) AS TOTAL, 1 AS FORCE_TRIGGER&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;FROM MY_TABLE&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;GROUP BY COLUMN_1, COLUMN_2&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The idea is that a scheduled job updates my_table and then runs the alert. The alert triggers when MIN(FORCE_TRIGGER) &amp;gt; 0 (in other words, each time it runs). It then sends me a notification via email with the query results included via the variable @QUERY_RESULT_TABLE.&lt;/P&gt;&lt;P&gt;The alert runs successfully and sends me an email. However, in it I only get a single row of query results.&lt;/P&gt;&lt;P&gt;Does anyone know how to get the full query results to display in the email please?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2026 14:25:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-show-full-query-results-in-a-sql-alert-s-notification/m-p/166318#M55555</guid>
      <dc:creator>SRJDB</dc:creator>
      <dc:date>2026-08-24T14:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to show full query results in a SQL alert's notification?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-show-full-query-results-in-a-sql-alert-s-notification/m-p/166324#M55557</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/199244"&gt;@SRJDB&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV&gt;The underlying issue is on how Databricks SQL processes aggregation functions in the alert trigger criteria. When you configure the alert condition using an aggregate like &lt;STRONG&gt;MIN&lt;/STRONG&gt;, MAX, AVG or SUM, the alert engine runs an evaluation pass that collapses the entire result set into a single scalar row. That single-row context gets passed into the result table variable in your notification template, which is why email only renders one record.&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;To preserve the complete table in your notification, switch the alert condition setting from MIN to &lt;STRONG&gt;FIRST_ROW&lt;/STRONG&gt;. Using FIRST_ROW instructs the alert to evaluate the trigger criteria against the first record's value while keeping the full query result set intact. The notification variable will then render all returned rows from your query up to the limit of 100 rows.&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 24 Aug 2026 15:32:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-show-full-query-results-in-a-sql-alert-s-notification/m-p/166324#M55557</guid>
      <dc:creator>balajij8</dc:creator>
      <dc:date>2026-08-24T15:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to show full query results in a SQL alert's notification?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-show-full-query-results-in-a-sql-alert-s-notification/m-p/166329#M55558</link>
      <description>&lt;P data-pm-slice="1 1 []"&gt;You are getting one row because of the &lt;CODE&gt;MIN&lt;/CODE&gt; in the alert condition rather than anything in the notification template. Setting an aggregation rewrites the query before it runs. From &lt;A href="https://docs.databricks.com/aws/en/sql/user/alerts/query-patterns" target="_blank"&gt;Alert query patterns&lt;/A&gt;: "The alert wraps the original query text in a common table expression (CTE) and performs a wrapping aggregation query on it to aggregate the query result", and "those variables will only display the final, post-aggregation query result." So with &lt;CODE&gt;MIN&lt;/CODE&gt; on &lt;CODE&gt;FORCE_TRIGGER&lt;/CODE&gt;, what executes is shaped like &lt;CODE&gt;WITH q AS (&amp;lt;your query&amp;gt;) SELECT MIN(FORCE_TRIGGER) FROM q&lt;/CODE&gt;, which returns exactly one row, and that single row is all &lt;CODE&gt;@QUERY_RESULT_TABLE&lt;/CODE&gt; has to render.&lt;/P&gt;
&lt;P&gt;To keep the always-fires pattern and still get every row:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;P&gt;Set the condition to &lt;STRONG&gt;First row&lt;/STRONG&gt; on &lt;CODE&gt;FORCE_TRIGGER&lt;/CODE&gt;, keeping &lt;CODE&gt;&amp;gt; 0&lt;/CODE&gt;. &lt;A href="https://docs.databricks.com/aws/en/sql/user/alerts/create" target="_blank"&gt;Create an alert&lt;/A&gt; describes the choice as "You can set an alert condition on the first value of a column in the query result, or you can select to set an aggregation across all rows of a single column, such as SUM or AVERAGE", and the &lt;A href="https://docs.databricks.com/api/workspace/alertsv2/createalert" target="_blank"&gt;Alerts API reference&lt;/A&gt; states that when &lt;CODE&gt;aggregation&lt;/CODE&gt; is not set, "the behavior is equivalent to using First row." With no aggregation there is no CTE rewrite, so the full result set reaches the template. Your &lt;CODE&gt;FORCE_TRIGGER&lt;/CODE&gt; column is &lt;CODE&gt;1&lt;/CODE&gt; on every row, so a first-row check still fires on every run, and it does not matter which row the evaluator picks.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Plan for the 100-row cap. &lt;A href="https://docs.databricks.com/aws/en/sql/user/alerts/create" target="_blank"&gt;Create an alert&lt;/A&gt; documents &lt;CODE&gt;QUERY_RESULT_TABLE&lt;/CODE&gt; as "The query result HTML table (string). Results are limited to the first 100 rows. Only email notification destinations can render HTML." If your grouped result can exceed 100 rows, adding an explicit &lt;CODE&gt;ORDER BY&lt;/CODE&gt; makes it predictable which rows land in the email.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Worth confirming with &lt;STRONG&gt;Test condition&lt;/STRONG&gt; in the alert editor before the next scheduled run, since that shows you the evaluation without waiting for the schedule.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2026 16:39:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-show-full-query-results-in-a-sql-alert-s-notification/m-p/166329#M55558</guid>
      <dc:creator>AbhilashNagilla</dc:creator>
      <dc:date>2026-08-24T16:39:12Z</dc:date>
    </item>
  </channel>
</rss>

