Query - Count

S

SAC

New help with count by in a query.

I have a Bill Of Lading items Table. A BOL can have several lines and
different vendors can be on different line or the same vendor can be on
different lines.

I'm trying to write a query that will count the number of vendors on a BOL.

I have:

SELECT BOLITMS.BOLNO, Count(BOLITMS.VENDNO) As CountOfVendNo
FROM BOLITMS
GROUP BY BOLITMS.BOLNO

I'm getting > 1 when there is only a single vendor for the bolno.

Any ideas?

Thanks.
 
D

Douglas J. Steele

Access doesn't allow you to count the values of a particular field like
that.

Create an intermediary query that returns only unique combinations of BOLNO
and VENDNO:

SELECT DISTINCT BOLNO, VENDNO
FROM BOLITMS

Base your count query on that query.

Assuming you're using Access 2000 or newer, you can do it all in one query:

SELECT BOLNO, Count(VENDNO) As CountOfVendNo
FROM
(
SELECT DISTINCT BOLNO, VENDNO
FROM BOLITMS
) AS Subquery
GROUP BY BOLNO
 
S

SAC

Excellent, Doug! Thanks.
Douglas J. Steele said:
Access doesn't allow you to count the values of a particular field like
that.

Create an intermediary query that returns only unique combinations of BOLNO
and VENDNO:

SELECT DISTINCT BOLNO, VENDNO
FROM BOLITMS

Base your count query on that query.

Assuming you're using Access 2000 or newer, you can do it all in one query:

SELECT BOLNO, Count(VENDNO) As CountOfVendNo
FROM
(
SELECT DISTINCT BOLNO, VENDNO
FROM BOLITMS
) AS Subquery
GROUP BY BOLNO
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Access MS Access Help with Select Distinct(count field) 0
How to use a recordset to validate and entry? 3
Count in a query 2
Errors using Analyze 3
Unique Count in Query 17
Count Unique Values 17
Query Criteria 4
Access Dcount (multiple criteria) 3

Top