Solved

Access 2007 - How do I count unique ID's

Posted on 2010-09-19
8
987 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 44

Expert Comment

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

Accepted Solution

by:
Rey Obrero (Capricorn1) 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 48

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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 …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

691 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