Access 2007 - How do I count unique ID's

I have a table with two columns of data.

Account ID
Contact ID

Please provide me with the SQL statement to use in Access 2007 to output a new table where each account ID appears only once and in the second column there is a column indicating the number of unique contact ID's for each account.
Who is Participating?
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
select [Account ID], count([contact ID])
from tablex
group by [account ID]
SELECT AccountID, Count(ContactID) as CountOfContacts FROM myTable GROUP BY AccountID;
rporter45Author Commented:
This one provided the exact syntax.
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.


SELECT a.AccountID Count(a.ContactID) AS CountUniqContacts FROM (
SELECT DistinctROW AccountID, ContactID FROM myTable) AS a GROUP BY a.AccountID;
Dale FyeCommented:
Well, if your current structure allows you to have multiple records with the same accountID and ContactID, then neither of the above will work.  You will first need to get DISTINCT combinations of AccountID and ContactID, so try:

SELECT T.[Account ID], Count(T.[Contact ID]) as UniqueContacts
FROM (SELECT DISTINCT [Account ID], [Contact ID] FROM your Table) as T
GROUP  BY T.[Account ID]
I believe you selected answer will count multiple ContactID's.
I have run tests and fyed's solution at http:#a33712457 is correct.  My solution in the previous post is not correct as I used DISTINCTROW instead of DISTINCT.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.