DKCroat
DKCroat

Reputation: 357

How to find accounts without primary holder

I have a table with account number, customers number and is primary flag (0 or 1). Account will have 1 or more customers. What function I can use to pull all accounts from table where account does NOT have primary on account. So example account # 12345 has 3 customers but all customers have 0 as primary flag?

Upvotes: 1

Views: 60

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270391

I would suggest aggregation:

select account_number
from accounts a 
group by account_number
having max(is_primary) = 0;

Upvotes: 1

Related Questions