Results 1 to 8 of 8
  1. #1
    EcologyHelp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    16

    Distinct Counts

    Hello,

    I am trying to generate a query with distinct counts. I have a list of plant names and I am trying to determine the number of occurrences for each plant species.
    Click image for larger version. 

Name:	Base_Query.PNG 
Views:	8 
Size:	28.7 KB 
ID:	24404
    The first picture is a piece of my database with a list of plant species. As you can see there are multiples of the same plants in that list. What I am trying to do is count the amount of times that each plant occurs in the list. It should look like the picture below.
    Click image for larger version. 

Name:	Distinct_Count.PNG 
Views:	8 
Size:	29.1 KB 
ID:	24405
    As you can see the list generated above is only returning a value of 1 for each plant species. I know that I have to do sub-queries, as Access does not support a direct DISTINCT function. Here is a picture of my SQL view to show what I have done, and probably where I have gone wrong.
    Click image for larger version. 

Name:	Distinct_Count_SQL.PNG 
Views:	8 
Size:	5.0 KB 
ID:	24406
    Please let me know if you need anymore information.



    Thank you in advance for any help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    SELECT SpeciesField, Count(*) As HowMany
    FROM TableName
    GROUP BY SpeciesField
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    EcologyHelp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    16
    Thanks so much I don't know why I was making it so complicated. I guess that's what happens when you are learning Access on the fly.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    EcologyHelp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    16
    Before I list this as solve I have one more question. I actually have multiple columns of plant species that I would like to get the total number of occurrence for each plant species (Plant Species database below). There is a total of 8 columns with plant species each column is titled PZ1_SP1_DominantSpecies, PZ1_SP2_DominantSpecies, and so on. I would like to generate an occurrence list for all plant species in that database (which has the name WSPZ1_Final1). Any help would be appreciated.
    .Click image for larger version. 

Name:	Base_Query_Multiple_PS.PNG 
Views:	7 
Size:	121.0 KB 
ID:	24407

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sounds like you have a normalization problem; those should probably be records in a related table, not fields in this one. If you're stuck with it, you can create a UNION query that joins the 8 fields into 1, then run your query against that.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    EcologyHelp is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2015
    Posts
    16
    I am not quite sure how to run a UNION query that joins columns from the same table.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    SELECT Field1
    FROM TableName
    UNION ALL
    SELECT Field2
    FROM TableName
    UNION ALL
    SELECT Field3
    FROM TableName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Adding to Counts
    By cree2me in forum Reports
    Replies: 2
    Last Post: 11-17-2014, 03:52 PM
  2. Numbers with sub counts
    By Thompyt in forum Access
    Replies: 8
    Last Post: 10-28-2014, 06:33 PM
  3. Why Are Counts Different?
    By johnywhy in forum Queries
    Replies: 9
    Last Post: 01-08-2014, 05:35 PM
  4. too many counts!
    By Svear in forum Access
    Replies: 1
    Last Post: 03-07-2012, 10:14 PM
  5. Counts in reports
    By beejay101 in forum Reports
    Replies: 2
    Last Post: 05-16-2011, 11:02 PM

Tags for this Thread

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