Results 1 to 4 of 4
  1. #1
    anziga is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    5

    Access DB distinct count

    I would like to count each distinct values from certain column in ACCESS DB. Let's say I have values like:


    1
    1
    1
    2
    3
    3
    3
    3
    I need to get the number of each distinct values and show the value, something like:
    1, 3
    2, 1
    3, 4
    I tried using:
    Code:
    qry = "SELECT COUNT(*) FROM (SELECT DISTINCT description FROM expenses GROUP BY description)"
    and some variations of this query, but e.g. this query just shows total number of distinct values. DB version is ACCESS 2k. Is there a way to do what I'm after?

  2. #2
    michaeljohnh is offline More Human than Human
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    61
    If I understand correctly, you simply need to make a query with 2 columns (no editting of SQL required). In Access 2007 there is a totals button when in design view of a query. Press it and a new row called Total appears. Drag and drop the column youre trying to group and count into 2 separate columns. With the Total function, set the first column to Group By which is what it should default to and set the second one to Count.
    Last edited by michaeljohnh; 10-12-2010 at 07:27 AM. Reason: editted for spelling

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Michael describe it in design view.
    I try to describe in SQL view since Anziga have CODE already:

    Code:
    qry = "SELECT COUNT(*), description FROM expenses GROUP BY description"

  4. #4
    anziga is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    5
    Sorry, I wasn't clear enough. I run this query from VB10, I'm not using actual ACCESS, just a database. I need to do a distinct count for one column only, and use the result elsewhere. This:
    Code:
    qry = "SELECT COUNT(*), description FROM expenses GROUP BY description"
    did the trick, thank you very much!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Count distinct records in parameterized query
    By SilverSN95 in forum Access
    Replies: 5
    Last Post: 07-27-2010, 09:31 AM
  2. Need help for distinct...
    By gunapriyan in forum Queries
    Replies: 2
    Last Post: 05-28-2010, 12:18 AM
  3. Replies: 2
    Last Post: 11-18-2009, 06:49 PM
  4. Distinct Values
    By Acramer8 in forum Reports
    Replies: 1
    Last Post: 06-15-2009, 08:37 AM
  5. Replies: 0
    Last Post: 08-08-2008, 08:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums