473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I count how many times each distinct entry in a column appears?

I am trying to get a exact count of different distinct entries in an
Access column. At first, I was trying to work with three columns, but
I've narrowed it down to one to simplify it. I've searched Google
Groups for Distinct Count and Count, the Microsoft Help file (which
apparently has bad links in Office 2003), and looked at other files,
but I can't find the answer. The closest I've been able to get is to
create a query to find the distinct entries, and to make a total count
of those (50000+), but I have a list of 200000+ entries, and I need to
know how many times those distinct items appears in the main list.

For example, my column looks like this:
First_Description
Description A
Description B
Description C
Description A
Description D
Description A
Description B

What I'd ultimately like to have is either a report, or a table that I
can export to Excel (since it's less than 65000 distinct rows) that
looks like this:
First_Description # of occurances
Description A 3
Description B 2
Description C 1
Description D 1

I know this may sound simple, but for the life of me, I can't figure it
out. The best I've done is this:
SELECT Count([First Descriptions].First_Description) AS
CountOfFirst_Description1, [First Descriptions].First_Description
FROM [Select Distinct], [First Descriptions]
GROUP BY [First Descriptions].First_Description
ORDER BY Count([First Descriptions].First_Description), [First
Descriptions].First_Description;

But, this query ran for over 5 hours last night, and it never came up.
I'm trying it again now, but I know it will be slow.
Thanks for all your help! It is appreciated!
Keith

Nov 13 '05 #1
17 16340
On 21 Jan 2005 06:06:41 -0800, ke***@s116160440.onlinehome.us wrote:

Create a new query, and select your table.
Drag the Description field to the grid TWICE.
Leave the first one at Group By.
Set the second one to Count.

-Tom.

I am trying to get a exact count of different distinct entries in an
Access column. At first, I was trying to work with three columns, but
I've narrowed it down to one to simplify it. I've searched Google
Groups for Distinct Count and Count, the Microsoft Help file (which
apparently has bad links in Office 2003), and looked at other files,
but I can't find the answer. The closest I've been able to get is to
create a query to find the distinct entries, and to make a total count
of those (50000+), but I have a list of 200000+ entries, and I need to
know how many times those distinct items appears in the main list.

For example, my column looks like this:
First_Description
Description A
Description B
Description C
Description A
Description D
Description A
Description B

What I'd ultimately like to have is either a report, or a table that I
can export to Excel (since it's less than 65000 distinct rows) that
looks like this:
First_Description # of occurances
Description A 3
Description B 2
Description C 1
Description D 1

I know this may sound simple, but for the life of me, I can't figure it
out. The best I've done is this:
SELECT Count([First Descriptions].First_Description) AS
CountOfFirst_Description1, [First Descriptions].First_Description
FROM [Select Distinct], [First Descriptions]
GROUP BY [First Descriptions].First_Description
ORDER BY Count([First Descriptions].First_Description), [First
Descriptions].First_Description;

But, this query ran for over 5 hours last night, and it never came up.
I'm trying it again now, but I know it will be slow.
Thanks for all your help! It is appreciated!
Keith


Nov 13 '05 #2
I'm trying it now (it's the reverse of how I had it). The query has now
run for the last two hours...hopefully it will pop up soon! I'll post
the outcome here.

Thanks!
Keith

Nov 13 '05 #3

You may wish to add an index to your 'Description' column to speed the
tabulation.

king ron of chi

Nov 13 '05 #4
Thanks Ron. I've left the query running since this morning and it's
still not done. I quit it and added the indexing property. Hopefully
this will work.

Nov 13 '05 #5
On 21 Jan 2005 13:11:56 -0800, ke***@s116160440.onlinehome.us wrote:

With an index, this should take less than a minute. Perhaps less than
5 seconds.

-Tom.

Thanks Ron. I've left the query running since this morning and it's
still not done. I quit it and added the indexing property. Hopefully
this will work.


Nov 13 '05 #6
Tom van Stiphout wrote:
On 21 Jan 2005 06:06:41 -0800, ke***@s116160440.onlinehome.us wrote:

Create a new query, and select your table.
Drag the Description field to the grid TWICE.
Leave the first one at Group By.
Set the second one to Count.

-Tom.


I left it running all weekend long...it never came up, even after I
indexed it. Is there anything else I could try?

Thanks,
Keith

Nov 13 '05 #7
rkc
ke***@s116160440.onlinehome.us wrote:
Tom van Stiphout wrote:
On 21 Jan 2005 06:06:41 -0800, ke***@s116160440.onlinehome.us wrote:

Create a new query, and select your table.
Drag the Description field to the grid TWICE.
Leave the first one at Group By.
Set the second one to Count.

-Tom.

I left it running all weekend long...it never came up, even after I
indexed it. Is there anything else I could try?


Have you considered moving smaller amounts of your data to
a test database until you get the query running correctly?

Nov 13 '05 #8
No, but I could try that. Thanks!

Nov 13 '05 #9
I cut it down from 200000+ records to 2614. There are now 936 unique
entries, but the script still is not working or it's just taking too
long to process. Finding the distinct entries takes a second or two, so
thanks for the indexing idea...that helps a bit.
Should I try this using VBA, and if so, how do I do that?

Nov 13 '05 #10
Ok, the query took about 3 hours with 2614 records. It worked...almost.
This is an example of what I received:

First_Description CountOfFirst_Description1
Emission limitation exceedance report 338612
Emission measurement summary 169306
Emission observation forms 169306
Emission reduction credits annual report 169306

There are obviously not 338612 entries, so I don't know why it's
displaying it as such. If I divide that number reported by 169306, I
get the correct number of times that it displays (I did a few random
checks).

Would anyone know why it's giving me these numbers? Is this the number
of passes the query had to make? It appears that this query will work
on a larger scale, but I don't know how long it will take to calculate.
But, I'll try again...

Nov 13 '05 #11
On 24 Jan 2005 05:19:31 -0800, ke***@s116160440.onlinehome.us wrote:
Tom van Stiphout wrote:
On 21 Jan 2005 06:06:41 -0800, ke***@s116160440.onlinehome.us wrote:

Create a new query, and select your table.
Drag the Description field to the grid TWICE.
Leave the first one at Group By.
Set the second one to Count.

-Tom.


I left it running all weekend long...it never came up, even after I
indexed it. Is there anything else I could try?

Thanks,
Keith


Post your SQL and a summary of the table definition.
Are you on a PC with limited memory?
If you group by the first character (left(xxx), 1), the first 5
characters (left(xxx, 5)) etc how long does that take?

David

Nov 13 '05 #12
SELECT [First Descriptions].First_Description, Count([First
Descriptions].First_Description) AS CountOfFirst_Description
FROM [First Descriptions], [First Descriptions] AS [First
Descriptions_1]
GROUP BY [First Descriptions].First_Description;

It has 512 MB of RAM, but I do work on it while letting it process.
However, I left it running since Friday with nothing in the background
and it still didn't finish.

I'm not sure I understand how you would group by the characters or the
code necessary to do it. I just have used the "Group By" setting in the
Query screen.

Nov 13 '05 #13
On 24 Jan 2005 11:24:16 -0800, ke***@s116160440.onlinehome.us wrote:
SELECT [First Descriptions].First_Description, Count([First
Descriptions].First_Description) AS CountOfFirst_Description
FROM [First Descriptions], [First Descriptions] AS [First
Descriptions_1]
GROUP BY [First Descriptions].First_Description;

It has 512 MB of RAM, but I do work on it while letting it process.
However, I left it running since Friday with nothing in the background
and it still didn't finish.

I'm not sure I understand how you would group by the characters or the
code necessary to do it. I just have used the "Group By" setting in the
Query screen.

Hi
I see.
You didn't follow Tom's instructions correctly I'm afraid, you should
have just dragged down the description field twice from one copy of
the table.
The query you want is

SELECT [First descriptions].[First Description], Count([First
descriptions].[First Description]) AS [CountOfFirst Description]
FROM [First descriptions]
GROUP BY [First descriptions].[First Description];

It is always worth posting the sql for any query you are discussing.

David

Nov 13 '05 #14
Thanks David. I tried entering in your query exactly as you have it,
and it popped up two boxes asking for information.

I'll try your method as I left this query running since Monday, and
still no results.

Arrgh..I know the answer is in front of me...I just can't see the
forest.

Nov 13 '05 #15
FYI...it finally worked. I did nothing different. I tried pulling down
the description twice (which I could've sworn I did), and all of a
sudden, the query results were there a few hours later.

I don't know if it took so long to do it initially, or if pulling the
description is what did it, but it works, and I am happy.
Thanks to all who helped!!!

Nov 13 '05 #16
On 26 Jan 2005 07:53:35 -0800, ke***@s116160440.onlinehome.us wrote:
Thanks David. I tried entering in your query exactly as you have it,
and it popped up two boxes asking for information.

I'll try your method as I left this query running since Monday, and
still no results.

Arrgh..I know the answer is in front of me...I just can't see the
forest.


Keith

If you looked at my query you will see that I referred to your table
as [First Descriptions] and your field as [First Description], while
in your post your field is actually [First_Description] with an
underscore rather than a space. So my query should have been

SELECT [First descriptions].[First_Description],
Count([First descriptions].[First_Description])
AS [CountOfFirst_Description]
FROM [First descriptions]
GROUP BY [First descriptions].[First_Description];

Sorry about that, but I think you should take the time to read up a
bit on using queries.
Your original query, apart from taking 200000 times longer to run (if
that is the number of records) will give answers that are 200000 times
too large.

David
Nov 13 '05 #17
I just need to read a bit more about everything, to be honest with you.
I just plug away, then when I need help, I read the help file/Google
Groups/MVPs.org...anywhere I can think of.

Are there any good books that would help a person who knows about
computers, but needs a bit of help with Access? There's tons on Amazon,
but any personal recommendations from this group would help.
Thanks again!
Keith

Nov 13 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Fisher | last post by:
I have a Java desktop GUI application that the user can run multiple times. In order to keep one instance of the application distinct from another, I'd like to put the instance number of the...
6
by: Christian | last post by:
HI, I have a function that is used to constrain a query: Select COl1, Col2 From MyTable WHERE col1 = ... AND col2 = ... And MyFunction(col1) = ... My problem is that MyFunction is executed...
1
by: Marcin Floryan | last post by:
Hello! My question regards opening (and re-opening) Form and the Load event. I have a main form (frmMain) and I also have a data form (frmData). In the main form I have created: Private...
2
by: Steve | last post by:
A main form contains ten textboxes and ten subforms. All ten subforms have the same query (Query2) for their recordsource. Query2 is based on a query (Query1). Each subform is linked to a different...
9
by: Manuel | last post by:
I have a Datagrid with 9 elements. The problem is that when I sort the grid by a column, it present more columns than there are. This is my code for the ItemCreated event: Private pNo As...
1
by: Joey Martin | last post by:
I've done this before but cannot remember how. I have a field (FIELDNAME) in a sql2k environment. I just need to know how many times an "_" appears in that field. Pretty simple, but I cannot...
5
by: kjmatthews | last post by:
I am designing a site but only have access to a Mac, equipped with Virtual PC. On IE6 is appears that, on some pages of this site, the navigation does not appear. I have put up a test case:...
3
by: Advo | last post by:
I've made a small search function as of here: if (stristr($bleh,$search_for)) { if(preg_match('/<title>(*)<\/title>/i', $bleh, $matches)) { $name = str_replace("./","/",$name); echo "<li><a...
3
by: sukatoa | last post by:
For example: Cat Dog Cow Rat Cat Cat Rat Cow
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.