Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Count distinct parent and child records

Posted on 2008-10-08
3
Medium Priority
?
472 Views
Last Modified: 2010-04-21
I have a query which returns a individual records where a parent-child realtionship exists. I would like to count the distinct parent records and distinct child records. Each parent can have >1 child, but for some reason the number of parent records  = child records which is incorrect. Here is an example

Parent Record 001 + Child Record 001
Parent Record 001 + Child Record 002
Parent Record 001 + Child Record 003

The result I am looking for would be 1 Parent + 3 Child on a single row returned in my query. It should be fairly simple, but I am stumped.
Thanks in advance for your help.
Chad
0
Comment
Question by:cpyatt05
[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
  • 2
3 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 22671217
I'm not sure the question you have asked is really what you want and it involves a few steps but...


To get the distinct parents you would do...

Select distinct parentid from table (save as query1)

For children you do the same thing.

Select distinct childid from table (save as query2)

Then you do a third query:
Select distinct (Select count(*) from query1) as ParentCount, (Select count(*) from query2) as ChildCount from anysmalltable

this gives you counts of distinct parents and distinct children in the table.
0
 

Author Comment

by:cpyatt05
ID: 22671356
I was hoping to do all of this in one query, but your solution works fine. Thanks for your help!
0
 

Author Closing Comment

by:cpyatt05
ID: 31504346
I thought it might be simple. I guess I just couldn't see it. Thanks again.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

721 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