I have a huge log table and I need to fetch some data for usage statistics. let's say we have a log table:
| user_id | action |
| 12345 | app: IOs |
| 12345 | app_version: 2018 |
| 12346 | app: Android |
| 12346 | app_version: 2019 |
| 12347 | app: Windows |
| 12347 | app_version: 2019 |
Is there a way to fetch all user ids who uses old(2018) mobile apps?
There is a way I did it but it is not efficient
SELECT
user_id
FROM
log
WHERE
action LIKE '%2018%'
AND
user_id IN (SELECT DISTINCT user_id FROM log WHERE(action LIKE '%IOs%' OR action LIKE '%Android%' ))
GROUP BY user_id
This query took about half an hour on production.
So in the end I want to have list of user ids as efficient as possible as I also will join another table to get their emails. What options do I have?