<?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>question Re: Select Statement Inside Case Statement In Impala in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Select-Statement-Inside-Case-Statement-In-Impala/m-p/387789#M246431</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/32170"&gt;@ChineduLB&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Impala doesn't directly support nested select statements within the WHEN clause of a CASE statement. However, you can achieve similar logic&lt;/P&gt;&lt;P&gt;Subqueries for conditions: You can use subqueries within the WHEN clause to evaluate conditions based on data retrieved from other tables.&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;case&lt;BR /&gt;when (select count(*) from table1) &amp;gt; 0 then (select * from table1)&lt;BR /&gt;when (select count(*) from table2) &amp;gt; 0 and (select count(*) from table3) &amp;gt; 0 then (select * from table3)&lt;BR /&gt;else null&lt;BR /&gt;end as result_table;&lt;/P&gt;&lt;P&gt;This query checks if table1 has any rows. If yes, it selects all columns from table1. Otherwise, it checks if both table2 and table3 have rows. If both have data, it selects all columns from table3. If none of the conditions are met, it returns null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 12 May 2024 08:37:37 GMT</pubDate>
    <dc:creator>RAGHUY</dc:creator>
    <dc:date>2024-05-12T08:37:37Z</dc:date>
    <item>
      <title>Select Statement Inside Case Statement In Impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Select-Statement-Inside-Case-Statement-In-Impala/m-p/387783#M246428</link>
      <description>&lt;P&gt;Is there a way to do something like:&lt;/P&gt;&lt;P&gt;case&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;when (select count(*) from table1 &amp;gt; 0) then (select * from table1)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;when (select count(*) from table2 &amp;gt; 0) and&amp;nbsp;(select count(*) from table3 &amp;gt; 0) then&amp;nbsp;(select * from table3)&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 11:03:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Select-Statement-Inside-Case-Statement-In-Impala/m-p/387783#M246428</guid>
      <dc:creator>ChineduLB</dc:creator>
      <dc:date>2024-05-11T11:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Select Statement Inside Case Statement In Impala</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Select-Statement-Inside-Case-Statement-In-Impala/m-p/387789#M246431</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/32170"&gt;@ChineduLB&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Impala doesn't directly support nested select statements within the WHEN clause of a CASE statement. However, you can achieve similar logic&lt;/P&gt;&lt;P&gt;Subqueries for conditions: You can use subqueries within the WHEN clause to evaluate conditions based on data retrieved from other tables.&lt;/P&gt;&lt;P&gt;SELECT&lt;BR /&gt;case&lt;BR /&gt;when (select count(*) from table1) &amp;gt; 0 then (select * from table1)&lt;BR /&gt;when (select count(*) from table2) &amp;gt; 0 and (select count(*) from table3) &amp;gt; 0 then (select * from table3)&lt;BR /&gt;else null&lt;BR /&gt;end as result_table;&lt;/P&gt;&lt;P&gt;This query checks if table1 has any rows. If yes, it selects all columns from table1. Otherwise, it checks if both table2 and table3 have rows. If both have data, it selects all columns from table3. If none of the conditions are met, it returns null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2024 08:37:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Select-Statement-Inside-Case-Statement-In-Impala/m-p/387789#M246431</guid>
      <dc:creator>RAGHUY</dc:creator>
      <dc:date>2024-05-12T08:37:37Z</dc:date>
    </item>
  </channel>
</rss>

