tags:

views:

342

answers:

1

This is probably an amateur question but I'm an amateur ! ;o)

I have several tables: Account table, Officer table, Location table, Web table... The Officer table doesn't give me the number of officers per account.

I need to retrieve only the accounts that have more than 20 officers. Should I use the COUNT ? If so, how ?

Your help is greatly appreciated. Thanks.

Pat

A: 

Update:

select a.id, a.eff-date, l.address, l.city, c.phonenumber
from Account a 
left outer join location l on a.id = l.id
left outer join contact c on a.id = c.id
where a.id in (
    select a.id
    from Account a
    inner join Officer ao on a.id = ao.id
    group by a.id
    having count(*) > 20    
)
RedFilter
ok.. here's the problemaccount table (id, eff-date etc)join officer table (id, officer number)join location table (id, address, city etc)left join contact table (id, phone number etc.)left join webinfo table (website, email, etc)the goal is to display only the id's that have more than 20 officer numbersorry for the lack of explanations... my bad ! thanks for your help.. really appreciate it
Pat
See my update. What are the relationships? Is the `id` column always representing Account ID?
RedFilter
yes id always representing account id... if i wanted to display id, eff-date, address, city, phone number when available but only those who have more than 20 officers... how would I code this ?
Pat
thank you very much ! appreciate it ! ;o)
Pat