- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Select Statement Inside Case Statement In Impala
- Labels:
-
Apache Impala
Created ‎05-11-2024 04:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a way to do something like:
case
when (select count(*) from table1 > 0) then (select * from table1)
when (select count(*) from table2 > 0) and (select count(*) from table3 > 0) then (select * from table3)
end
Created ‎05-12-2024 01:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Impala doesn't directly support nested select statements within the WHEN clause of a CASE statement. However, you can achieve similar logic
Subqueries for conditions: You can use subqueries within the WHEN clause to evaluate conditions based on data retrieved from other tables.
SELECT
case
when (select count(*) from table1) > 0 then (select * from table1)
when (select count(*) from table2) > 0 and (select count(*) from table3) > 0 then (select * from table3)
else null
end as result_table;
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.
Created ‎05-12-2024 01:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Impala doesn't directly support nested select statements within the WHEN clause of a CASE statement. However, you can achieve similar logic
Subqueries for conditions: You can use subqueries within the WHEN clause to evaluate conditions based on data retrieved from other tables.
SELECT
case
when (select count(*) from table1) > 0 then (select * from table1)
when (select count(*) from table2) > 0 and (select count(*) from table3) > 0 then (select * from table3)
else null
end as result_table;
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.
