Skip to content
Advertisement

Querying specific relation that doesnt have a value on a column

I have the following tables:

  • Person (id, name, address)

  • Person_subscription (id, person_id, status)

Does a person have many subscriptions but no active one? get that person as ‘Ex-Customer’

Does a person have an active subscription? get that person as ‘Customer’

Ignore customers who don’t have any subscriptions.

The above query will bring out the selected person as an example.

But I’ll have two rows with conflicting values. My goal is to unify those rows into one and determine the condition set above.

The above query doesn’t yield any results.

What’s my best bet here, how to proceed?

Advertisement

Answer

You can use distinct on:

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