Solved

Access 2007 - How do I count unique ID's

Posted on 2010-09-19
8
941 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:rporter45
8 Comments
 
LVL 44

Expert Comment

by:GRayL
ID: 33712437
SELECT AccountID, Count(ContactID) as CountOfContacts FROM myTable GROUP BY AccountID;
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 33712440
select [Account ID], count([contact ID])
from tablex
group by [account ID]
0
 

Author Closing Comment

by:rporter45
ID: 33712451
This one provided the exact syntax.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 44

Expert Comment

by:GRayL
ID: 33712453
Oops:

SELECT a.AccountID Count(a.ContactID) AS CountUniqContacts FROM (
SELECT DistinctROW AccountID, ContactID FROM myTable) AS a GROUP BY a.AccountID;
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33712457
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
 
LVL 44

Expert Comment

by:GRayL
ID: 33712458
I believe you selected answer will count multiple ContactID's.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 33719434
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now