Reputation: 4262
I am looking for most efficient query to fetch Customer name who have either paid for all the orders they have placed with us or have not placed order at all.Following is the table structure:
Customer to Order is one to many relationship.
Payment status can only be PAID OR UNPAID.
Following is sample data and result which I am expecting.
Thanks alot!
Upvotes: 0
Views: 856
Reputation: 17915
select *
from customer c
where not exists (
select 1 from "order" o
where o.cust_id = c.cust_id and payment_status = 'UNPAID'
)
Upvotes: 3