Results 1 to 2 of 2
  1. #1
    dlong is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    1

    How to only see results in a query if the primary key shows up a minimum number of times in the list

    Hello, I have very very limited Access knowledge and a very cursory knowledge of SQL commands, so I'm having a lot of trouble making this happen although I'm sure it can be done.

    I am trying to make a query that only shows me results for primary keys that have at least 4 results. Specifically, the primary keys are student ID's, and each result is a course the student took. I only want results in my query for students who took at least 4 courses. I was able to figure out how to limit by time period, but this stumping me.

    Things I already tried (but maybe not very well):

    --Using "count" in the criteria field for Student_ID (syntax may have been off)
    --Adding a count under WHERE in the SQL view (syntax was almost definitely off)

    Thanks in advance for any help.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Try

    SELECT * FROM Students WHERE DCount("*","StudentCourses","Student_ID=" & [Student_ID)>=4;

    or

    SELECT * FROM Students WHERE Student_ID IN (SELECT Student_ID FROM StudentCourses GROUP BY Student_ID HAVING Count("*")>=4);

    or

    SELECT * FROM Students INNER JOIN (SELECT Student_ID FROM StudentCourses GROUP BY Student_ID HAVING Count("*")>=4) AS Q1 ON Students.Student_ID=Q1.Student_ID;
    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.

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

Similar Threads

  1. Replies: 1
    Last Post: 01-12-2018, 07:13 AM
  2. Replies: 3
    Last Post: 01-11-2018, 08:12 PM
  3. Replies: 8
    Last Post: 12-13-2017, 10:38 AM
  4. Replies: 4
    Last Post: 04-06-2016, 05:37 AM
  5. Replies: 14
    Last Post: 02-23-2012, 06:32 PM

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