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.
rporter45Asked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
select [Account ID], count([contact ID])
from tablex
group by [account ID]
0
 
GRayLCommented:
SELECT AccountID, Count(ContactID) as CountOfContacts FROM myTable GROUP BY AccountID;
0
 
rporter45Author Commented:
This one provided the exact syntax.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
GRayLCommented:
Oops:

SELECT a.AccountID Count(a.ContactID) AS CountUniqContacts FROM (
SELECT DistinctROW AccountID, ContactID FROM myTable) AS a GROUP BY a.AccountID;
0
 
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]
0
 
GRayLCommented:
I believe you selected answer will count multiple ContactID's.
0
 
GRayLCommented:
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.
0
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.