0

I want to count a bunch of entries past a date. However, I also want to have results that say 0. But the current query drops all 0 results as soon as i add the filter by date clause. Any ideas how to get those 0 entries?

select distinct (e.customer_id), count(m.id) as msgs from eng_msgs e
join messages m on e.customer_id = m.customer_id
where e.customer_id = m.customer_id
and m.created_at > e.created_at -- this line removes 0 results
group by e.customer_id 

1 Answer 1

1

You need an outer join condition:

select e.customer_id, count(m.id) as msgs
from
    eng_msgs e
    left outer join
    messages m on
        e.customer_id = m.customer_id
        and
        m.created_at > e.created_at
group by e.customer_id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.