Return all rows for ID where a condition is met on one row

Viewed 87

Im really new to sql and have written a query like this in Athena:

CREATE OR REPLACE VIEW vw_em AS 
SELECT *
FROM
  s_prod_m.metm_inm
WHERE ((channel IN (SELECT msn
FROM
  smartco_prod_meterdata.meter_interval
WHERE (channel = '1825')
)) AND (interval_date BETWEEN (current_date - INTERVAL  '1' MONTH) AND current_date))

Basically what Im trying to do is return all rows for an ID (msn) if any of the rows have 1825 in the channel column.

The query works in that it creates a view for me but when I try to preview the view with a limit of 10 it takes ages to run (I stopped it after 10 mins) so I dont know if this is even the correct way of doing it, if it isnt can someone help with a solution if it is, is there a better/faster way to achieve this result?

Thanks

0 Answers
Related