Distinct query method

  • Thread starter Thread starter Jessica
  • Start date Start date
J

Jessica

Greetings!

In my table I have two fields: year, collection.
Collection is not a unique field, but what I want to do is
create a query that counts the number of unique
collections per year. The only way I was able to do this
was to first create a query that used the used the totals
functions to group by year and collection number, and then
run a second query on that query that counted the number
of collections in each year. Is there a way to do this
using the distinct row or field function that will still
give me the same count?

Thanks!
Jessica
 
No, but you could do it using a subquery, so you only have to store
one query in your database.

SELECT T.Year, Count(T.Collection) as CollectionCount
FROM (SELECT Distinct Year, Collection
FROM yourTable) as T
GROUP BY T.Year

--
HTH

Dale Fye


Greetings!

In my table I have two fields: year, collection.
Collection is not a unique field, but what I want to do is
create a query that counts the number of unique
collections per year. The only way I was able to do this
was to first create a query that used the used the totals
functions to group by year and collection number, and then
run a second query on that query that counted the number
of collections in each year. Is there a way to do this
using the distinct row or field function that will still
give me the same count?

Thanks!
Jessica
 
You are welcome!

--
HTH

Dale Fye


Thanks that worked! I didn't realize you could use
subqueries.
 

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

COUNT and DISTINCT in Access 3
Dsum Problem 2
Combining Queries 2
Counting distinct? 2
Complex query 0
Help on Counting and grouping distinct records 3
delete identical duplicate records 1
Count Distinct Syntax 3

Back
Top