Share via

How to design this query

Rob Curtis 0 Reputation points
2026-03-13T15:36:51.5833333+00:00

I wanted to find all the species shot at a location in a period before 1990. I created one query for the number of species, but when I try to put the time period in I lose the count and get everyinstances of each record. So this would jump from 908 types to thousands of instances. User's image

This query had duplicates so I have 874 with just Montrose Point. I was trying to make a query based on this query but kept having the non-exclusive problem.

Microsoft 365 and Office | Access | Other | Windows

5 answers

Sort by: Most helpful
  1. Rob Curtis 0 Reputation points
    2026-03-14T12:53:09.3733333+00:00

    George, thanks again for the updated suggestion, which I can't see here. I tried that and .changing some locations to explore. It is unusual that I accessed this forum from a saved link which knows my password and everything.

    Yet when I go to the email, to see the latest post I have to sign in to answer, and that takes me to GoDaddy, where it doesn't accept my current password and then I have to change with the code sent, and then even after that it doesn't accept. I just went through all this days ago and had to call Godaddy as reset wasn't working and wait over a half hour for an answer and then go back and forth. Then it worked and now it didn't again, and I don't want to spend that time now.

    I am going to look at the SQL more and see if I can use different parameters such as my city or state fields. One thing I don't understand is, doesn't this Access have a "save as". If I just go to close, it asks if I want to save and then will wipe out whatever was there before making changes. Copying and pasting a duplicate isn't good, because copy doesn't appear available till it's closed, but then I would lose the original.

    Was this answer helpful?

    0 comments No comments

  2. Rob Curtis 0 Reputation points
    2026-03-13T22:32:29.7366667+00:00

    I must be seeming somewhat dull here, but I am trying to get it. I started a new query, and pasted in the lines in SQL (I didn't know I could start out with no tables). I made a couple of corrections, as it is slides 1 (slide 1 not found) and it is for records before 1990, not 1900.

    So: SELECT [Slides 1].Location, [Slides 1].Species, Count(*) AS Expr1

    FROM [Slides 1]

    WHERE ((([Slides 1].[Date_1])<=#1/1/1990#))

    GROUP BY [Slides 1].Location, [Slides 1].Species;

    This gave one table, with 1232 results. I then used this query instead of the slides 1 table and connected. I didn't see the field slides 1 but the result, with 63 species, seems it may be right. Because of the hidden parameters, is sorts phylogenetically instead of alphabetically, as I prefer. Thanks very much for your help!User's image

    User's image

    Was this answer helpful?


  3. Rob Curtis 0 Reputation points
    2026-03-13T16:00:40.9266667+00:00

    Duplication here.

    || || Query2

    CountOfCountOfSLIDE_# LOCATION DATE_1 CountOfSUBJECT SPECIES
    1 Montrose Point 9/9/1988 1 Agelaius phoeniceus
    1 Montrose Point 9/9/1988 1 Agelaius phoeniceus
    1 Montrose Point 9/1/1987 1 Ammodramus leconteii
    1 Montrose Point 9/29/1989 1 Ammodramus leconteii
    1 Montrose Point 9/21/1988 1 Ammospiza nelsoni
    1 Montrose Point 11/13/1988 1 Anas platyrhynchos
    1 Montrose Point 10/1/1988 1 Asio flammeus
    1 Montrose Point 9/26/1988 1 Aythya affinis
    1 Montrose Point 11/13/1988 1 Aythya affinis
    1 Montrose Point 10/28/1989 1 Botaurus lentiginosus
    1 Montrose Point 9/23/1989 1 Calcarius lapponicus
    1 Montrose Point 9/24/1989 1 Calcarius lapponicus
    1 Montrose Point 10/29/1989 1 Calcarius lapponicus
    1 Montrose Point 9/7/1988 1 Calidris alba
    1 Montrose Point 9/8/1988 1 Calidris alba
    1 Montrose Point 8/25/1989 1 Calidris alba
    1 Montrose Point 9/26/1988 1 Calidris alpina
    1 Montrose Point 9/8/1988 1 Calidris bairdii
    1 Montrose Point 8/25/1989 1 Calidris bairdii
    1 Montrose Point 9/8/1988 1 Calidris canutus
    1 Montrose Point 9/9/1988 1 Calidris canutus
    1 Montrose Point 9/15/1988 1 Calidris canutus
    1 Montrose Point 8/1/1989 1 Calidris canutus

    Was this answer helpful?

    0 comments No comments

  4. Rob Curtis 0 Reputation points
    2026-03-13T15:52:59.3+00:00

    The AI can't see that I already made such a query in the pictures. Before the date, there are 874 different species. With the date, that drops to 118 records but there are duplicates of the species. How to set that up to get rid of the extras I'm still stuck.

    Was this answer helpful?

    0 comments No comments

  5. AI answer

    2026-03-13T15:37:10.9533333+00:00

    Use a totals (aggregate) query that groups only by the fields that define a unique species at a location, and put the date restriction in the criteria for the date field.

    In Design view of the query:

    1. Add the table that contains the shots (Slides 1) and any lookup tables that define species.
    2. Add these fields to the grid:
      • LOCATION (from Slides 1)
      • SPECIES (from Slides 1 or the related table that uniquely identifies a species)
      • DATE_1 (the date the shot was taken)
    3. On the Design tab, click Totals so the Total row appears.
    4. Set the Total row as follows:
      • LOCATION: Group By
      • SPECIES: Group By
      • DATE_1: Where
    5. In the Criteria row under DATE_1 enter the date condition, for example:
      • <= #12/31/1989# (all shots before 1990)
    6. Add a new column to count distinct species per location:
      • Field: SpeciesCount: SPECIES
      • Total: Count

    This design:

    • Filters records to only those at Montrose (keep LOCATION criteria like Like "Montrose*" if needed).
    • Restricts records to dates before 1990 via the Where clause on DATE_1.
    • Groups by LOCATION and SPECIES so each species at that location is counted once.
    • Uses Count to return the number of species, not every instance.

    If duplicates still appear, add additional grouping fields that distinguish species (for example, SUBJECT or an identifier) or use a separate totals query first to get unique species per location, then base a second query on that totals query to count the rows.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.