Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:33:01+00:00 2026-06-11T09:33:01+00:00

Among the fields in my table are 2 fields, CTN_NUM and PO_NUM. Each PO_NUM

  • 0

Among the fields in my table are 2 fields, CTN_NUM and PO_NUM. Each PO_NUM has at least one CTN_NUM, possibly more—distinct or repeated. Any given CTN_NUM cannot have more than 1 PO_NUM. In other words, it’s a one to many relationship. I want to create a query which shows the number of unique CTN_NUM’s per PO_NUM. I’ve seen other threads on this forum as well as http://blogs.office.com/b/microsoft-access/archive/2007/09/19/writing-a-count-distinct-query-in-access.aspx and none seem to address this exact issue.
Here’s what I tried:

A)

SELECT PO_NUM, Count(CTN_NUM) AS CountOfCTN_NUM  
FROM tempSpring_ASN  
GROUP BY PO_NUM;  

This returns the count of ALL CTN_NUMs per PO_NUM, even if they are not unique.

B)

SELECT PO_NUM, Count(DISTINCT CTN_NUM) AS CountOfCTN_NUM  
FROM tempSpring_ASN  
GROUP BY PO_NUM;  

While this may work in other RDBMS’s, in Access I get a syntax error.

C)

SELECT COUNT(*)  
FROM  
(SELECT DISTINCT CTN_NUM AS cn  
FROM tempSpring_ASN);  

This returns the sum of CTN_NUM’s which are distinct to the table, not distinct to the PO_NUM.

D) Same as C, but with a GROUP BY:

SELECT COUNT(*)  
FROM  
(SELECT DISTINCT CTN_NUM AS cn  
FROM tempSpring_ASN)  
GROUP BY PO_NUM;  

This prompts me for the PO_NUM.

Can you please advise? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:33:02+00:00Added an answer on June 11, 2026 at 9:33 am

    Try this one:

    SELECT PO_NUM, COUNT(*) AS CountOfCTN_NUM    
    FROM   (
        SELECT PO_NUM, CTN_NUM 
        FROM tempSpring_ASN
        GROUP BY PO_NUM, CTN_NUM 
    ) a
    GROUP BY PO_NUM;   
    

    This should also work:

    SELECT PO_NUM, COUNT(*) AS CountOfCTN_NUM   
    FROM   (
        SELECT DISTINCT PO_NUM, CTN_NUM 
        FROM tempSpring_ASN
    ) a
    GROUP BY PO_NUM;   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my particular case, we've got a db table that, among other fields, has
Hi all I have an appointments table that has among other fields a DATE
What I have is a table that has different fields and among them the
I have a Table with 5 fields. among 5 columns one is PK. my
I have an unusual SQL table (not mine) which has the following fields (among
I have a table that consists of, among other things, two fields named StartTime
I have a table that has, among its primary keys, a VARCHAR(16) column that
I have a table called events with 5 fields. Among those fields I have
In my table I have two fields among others : article_id and version Example:
I've got a MySQL table with, among other things, two fields: a (int) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.