Results 1 to 10 of 10
  1. #1
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18

    find students that showed up for 2 specific dates

    Hi there,



    I am in a bit of a duh moment.... 1 table with students ID's and names along with a date... kind of a roster... I want to be able to query the table and get ONLY students that showed up for 2 specific dates (not range, but 2 individual dates)... I have been looking way to long to the dup expression builder statement and I cannot figur out how o include to only get the dups with a specific date (2).

    Any ideas or suggestions will be greatly appreciated

    Table1
    ID
    Date in

    parameters: [first date] [second date]

    find in Table 1 all ID's that were present in both dates: 1-7 and 1-12

    thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    What exactly does this represent 1-7 and 1-12?

    For reference,
    use meaningful table names
    don't use a naming convention that uses embedded spaces in names
    show readers what you have tried

    Good luck with your project.

  3. #3
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    >>What exactly does this represent 1-7 and 1-12?

    both dates: 1-7 and 1-12

    they represent dates: January 7 and January 12

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850

  5. #5
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    table only has this year, so no... I guess if year included could help for future year queries (if I continue to use it longer than this year)... thanks for asking

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You can get the list of student ID's with a simple query, which you can then use to filter other queries by Student_ID. You need two because the first one has a group by in it, which limits the number of fields you can put in.

    For example: I have a stamp collection, and I want to know which countries have both stamp number 1800 AND 1900 in the collection. In query design view, I do this:

    Click image for larger version. 

Name:	Screenshot (2).png 
Views:	23 
Size:	137.2 KB 
ID:	32321

    The SQL for the query is this (with the table name usually removed to make it easier to read:

    SELECT COUNTRYNUM, Count(COUNTRYNUM) AS CountOfCOUNTRYNUM
    FROM [Main Collection]
    WHERE (FIRST=1800 Or FIRST=1900)
    GROUP BY COUNTRYNUM
    HAVING Count(COUNTRYNUM)>1;


    Notice COUNTRYNUM is in the query twice - first to group by and display, and second to count how many times it occurs.
    Notice too that the two conditions are joined with OR; if both of them are met, then the count will be > 1.

    You would replace COUNTRYNUM with Student_ID, FIRST with the name of your date field, and Main Collection with the name of your table. (I know - shouldn't use spaces in table names)

    Once you have this working, you would join it to other queries on Student_ID to filter the data they show.

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Redid the query with my sample data

    Code:
    PARAMETERS  [Date1]  datetime, [date2]  datetime;
    SELECT AnimalID 
    FROM AnimalLocs as A
    WHERE A.SightingDate = [date1]
    AND
     a.animalID  in (SELECT  AnimalID 
    FROM AnimalLocs as B
    WHERE  b.SightingDate =[date2] )
    Hope it's useful.

  8. #8
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    Hi John_G,

    Thanks for the idea. I will try it as soon as I get my Network back (split DB).... One difference is that I want user to enter the dates (criteria)... in your example would having the popup to input 1800 and 1900 and the run the query, this will need to be done I assume with parameters, I think this is what I was thinking but I have not been able to get it to work... let me try and I will post the outcome.... thanks again!

    Quote Originally Posted by John_G View Post
    You can get the list of student ID's with a simple query, which you can then use to filter other queries by Student_ID. You need two because the first one has a group by in it, which limits the number of fields you can put in.

    For example: I have a stamp collection, and I want to know which countries have both stamp number 1800 AND 1900 in the collection. In query design view, I do this:

    Click image for larger version. 

Name:	Screenshot (2).png 
Views:	23 
Size:	137.2 KB 
ID:	32321

    The SQL for the query is this (with the table name usually removed to make it easier to read:

    SELECT COUNTRYNUM, Count(COUNTRYNUM) AS CountOfCOUNTRYNUM
    FROM [Main Collection]
    WHERE (FIRST=1800 Or FIRST=1900)
    GROUP BY COUNTRYNUM
    HAVING Count(COUNTRYNUM)>1;


    Notice COUNTRYNUM is in the query twice - first to group by and display, and second to count how many times it occurs.
    Notice too that the two conditions are joined with OR; if both of them are met, then the count will be > 1.

    You would replace COUNTRYNUM with Student_ID, FIRST with the name of your date field, and Main Collection with the name of your table. (I know - shouldn't use spaces in table names)

    Once you have this working, you would join it to other queries on Student_ID to filter the data they show.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Possibly another approach:

    SELECT * FROM table WHERE [datefield]=#1/7/2007# AND StudID IN (SELECT StudID FROM table WHERE [datefield]=#1/12/2007#);


    If you want dynamic parameterized query, recommend not utilizing popup input prompt. Have user enter values on a form and the query references the controls on form. This way you can validate user input.


    Also advise no spaces nor punctuation/special characters (underscore only exception) in naming convention.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    John_G,

    I am sorry for the delayed reply: it worked perfect, thanks!!!!

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

Similar Threads

  1. Find 2 most recent dates
    By cmiley in forum Queries
    Replies: 17
    Last Post: 01-19-2017, 04:57 PM
  2. Find gaps in Dates
    By soldat452002 in forum Queries
    Replies: 5
    Last Post: 07-31-2016, 03:57 PM
  3. Replies: 2
    Last Post: 07-25-2016, 08:12 AM
  4. Replies: 10
    Last Post: 11-05-2015, 02:22 PM
  5. find students with GPA 3.0 and above
    By primobolan in forum Access
    Replies: 1
    Last Post: 11-08-2013, 07:50 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