I have a query that is giving me the error above. My code is the following:
SELECT *,
dense_rank() OVER (PARTITION BY email
ORDER BY priority_score,
comp) AS r
FROM main_query
WHERE NOT EXISTS
(SELECT name,
event,
email,
report_date
FROM gm
WHERE gm.name= main_query.name
AND gm.event= main_query.event
AND gm.email = main_query.email
AND gm.report_date >= (CURRENT_DATE - 25)::date)
ORDER BY priority_score ASC
One solution that I saw to overcome these types of errors was to be able to transform correlated subqueries in queries not correlated (sherlock). Therefore, I am searching for other ways of using the where not exists statement but without a correlated subquery, i.e., calling the main_query table inside the subquery ((...) from gm left join main_query on(...)). Does anyone know if this is possible and how to do it?
Any advice is more than welcome and thanks a lot in advance!
Does a
LEFT JOINversion work?If that doesn't work, it should work like this: