Results 1 to 10 of 10
  1. #1
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57

    Student/lecture latest query,

    Lectures presented by all the students during the last year has been stored in a talbe named: studentlectures, with these fields :
    ID, studentname, lecturesubject, lecturedate
    For example:
    1, john, mathematics, 2/3/2012
    2, jack, chemistry, 10/3/2012 ,
    3,john, engineering, 15/3/2012
    4,jack ,chemisty,20/3/2012
    5,john,politics,30/3/2012
    6,john,engineering, 15/4/2012
    7,jack,politics,15/4/2012
    We want a query to show the latest record for each student with a specific lecture. For the above example the result will be:
    1, john, mathematics, 2/3/2012
    4, jack , chemisty,20/3/2012
    5,john, politics,30/3/2012


    6, john, engineering, 15/4/2012
    7, jack,politics,15/4/2012
    Previous subject records by each student are not shown, and only the latest one is shown.
    Thank you

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I recommend you review sql, aggregate functions and Group BY statement
    http://www.w3schools.com/sql/sql_groupby.asp

  3. #3
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    can anyone help on this please?

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    What have you tried that isn't working, since you read the information in the link provided ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    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,870
    Cross posted at https://www.access-programmers.co.uk...96#post1588596

    Since this thread started in April 2013, I have to wonder Why did you come back to it 5 years later still seeking an answer?


  6. #6
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    If my table had only three fields groupby would finelywork. In fact the real table has other fields, such as professorname,audiancenumbers, roomname, and else. If i make others "groupby" aswell, i dont get only the last reacord for a given student/lecture.
    After all, i couldn’t find any example on that page similarto what i am looking for.

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    The simple way to achieve this - Perform the grouping you need to get just the record ID's you need. Save this query as qryGrouped . Now get your original table create a new query with all the fields you need, add qryGrouped and link the two by ID.

    There are more elegant ways of doing this but this will give you a starting point.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    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,870
    Here is some sql that may help

    Code:
    SELECT A.id
        ,A.studentname
        ,A.lecturesubject
        ,A.lecturedate
    FROM arian AS A
    WHERE (
            (
                (A.lecturedate) IN (
                    SELECT TOP 1 b.lectureDate
                    FROM arian AS B
                    WHERE b.lecturesubject = a.lecturesubject
                        AND b.studentname = a.Studentname
                    ORDER BY b.lecturedate DESC
                    )
                )
            )
    GROUP BY  A.id
        ,A.studentname
        ,A.lecturesubject
        ,A.lecturedate
    ORDER BY A.lecturedate ASC
        ,A.studentname
        ,A.lecturesubject;
    With this result

    Code:
    id studentname lecturesubject lecturedate
    1 john mathematics 02-Mar-12
    2 jack chemistry 10-Mar-12
    4 jack chemisty 20-Mar-12
    5 john politics 30-Mar-12
    7 jack politics 15-Apr-12
    6 john engineering 15-Apr-12
    NOTE: You have 2 spellings for Chemistry (and Chemisty)

    When I correct the spelling, I get this result with the query identified above

    Code:
    id studentname lecturesubject lecturedate
    1 john mathematics 02-Mar-12
    4 jack chemistry 20-Mar-12
    5 john politics 30-Mar-12
    7 jack politics 15-Apr-12
    6 john engineering 15-Apr-12
    Good luck with your project

  9. #9
    ariansman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    57
    It worked. thank you very much

  10. #10
    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,870
    You are welcome. Can you tell us why there is a 5 yr gap between posts?

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

Similar Threads

  1. Append Query - Student Attendance
    By Daryl2106 in forum Access
    Replies: 5
    Last Post: 10-24-2012, 01:42 PM
  2. Student Payment Query not working
    By jcpty in forum Queries
    Replies: 10
    Last Post: 12-28-2011, 12:22 AM
  3. Join Query for Student Grades Database
    By usmcgrunt in forum Queries
    Replies: 2
    Last Post: 04-15-2011, 07:37 PM
  4. Query latest record
    By asherbear in forum Queries
    Replies: 5
    Last Post: 08-02-2010, 03:58 PM
  5. Create student teams via query?
    By jmccullough in forum Programming
    Replies: 0
    Last Post: 08-19-2009, 08:21 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