Home > Enterprise >  UNION ALL for several subqueries takes a long time
UNION ALL for several subqueries takes a long time

Time:01-26

I'm trying to count several items in the same table below:

food
apple cider
cake manzana (manzana in spanish == apple)
carrot cake
banana pudding

I want end up with the following table:

food count
apple 2
carrot 1
banana 1

I tried the following query which works for counting the apples:

SELECT 'apple' as placeholder, COUNT(*)
FROM table WHERE (food LIKE '%apple%' OR food LIKE '%manzana%') and date > '10/10/2021'

The issue is that when I try to expand it to get all of the food items together, it takes a long while:

SELECT 'apple' as placeholder, COUNT(*) FROM table WHERE (food LIKE '%apple%' OR food LIKE '%manzana%') and date > '10/10/2021' and ...
UNION ALL
SELECT 'carrot' as placeholder, COUNT(*) FROM table WHERE food LIKE '           
  •  Tags:  
  • Related