K
K
Konstantin Eliseev2019-05-30 18:01:40
PostgreSQL
Konstantin Eliseev, 2019-05-30 18:01:40

How to write a query to display data where the date is not equal to the given one?

subscriptions table (id, user_id, created_at, updated_at)
subscription_stats table (id, user_id, date)
Output without where:

select * from "subscriptions"
left join "subscription_stats"
on "subscriptions"."user_id" = "subscription_stats"."user_id"
limit 20

5cefef4785af8177194713.png
How to display a list of users whose date is not equal to the given one? I've tried both <> and != and it doesn't output anything...
select * from "subscriptions"
left join "subscription_stats"
on "subscriptions"."user_id" = "subscription_stats"."user_id"
where "subscription_stats"."date" <> '2019-05-16'

Decision:
select "subscriptions"."user_id" from "subscriptions"
left join "subscription_stats"
on "subscriptions"."user_id" = "subscription_stats"."user_id"
where ("subscription_stats"."date" <> '2019-05-16' or ("subscription_stats"."date") is null)
limit 20

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery, 2019-05-30
@Desay

Are you sure you need a left join?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question