Skip to content
Advertisement

Select all subscriptions whose users don’t have any other active subscription

I am writing a subscription cleanup query that should select all canceled subscriptions, whose users don’t have any other active subscription (the application allows multiple subscriptions per user).

I started with this:

However, I feel there must be an easier/more straightforward/more performant way.

Advertisement

Answer

NOT EXISTS can be more intuitive here:

You can also use a LEFT JOIN here:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement