Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access 2007 - How do I count unique ID's

Posted on 2010-09-19
8
Medium Priority
?
1,000 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 2000 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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
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

Technology Partners: 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!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

610 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