Results 1 to 7 of 7
  1. #1
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63

    Update records query...new to sql

    Hi. I am very new to programming and sql. Right now I am creating a gradebook to hold student's courses, grades, and teachers.



    Students may be able to retake a subject and thereby receive a different grade than first obtained. I would like to create a query that shows only the most recent grade a student received for any subject.

    I have the following query to do such for Social Studies:

    SELECT tbl_SocialStudies.ID, tbl_SocialStudies.Name, tbl_SocialStudies.Score, tbl_SocialStudies.Date
    FROM tbl_SocialStudies RIGHT JOIN [SELECT Name, Max(Date) AS Latest FROM tbl_SocialStudies GROUP BY Name]. AS Recent ON (tbl_SocialStudies.Name=Recent.Name) AND (tbl_SocialStudies.Date=Recent.Latest);

    Which runs fine. However, for some reason this keeps switching to:
    SELECT tbl_SocialStudies.ID, tbl_SocialStudies.Name, tbl_SocialStudies.Score, tbl_SocialStudies.Date
    FROM tbl_SocialStudies RIGHT JOIN [SELECT Name, Max(Date) AS Latest FROM tbl_SocialStudies GROUP BY Name; ] AS Recent ON (tbl_SocialStudies.Name=Recent.Name) AND (tbl_SocialStudies.Date=Recent.Latest);

    In the GROUP BY clause Name]. keeps jumping to Name;] after the query is saved. I have to keep fixing it everytime I want to see the results.

    Is there a particular reason why this is happening.

  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,640
    I would simply leave it as two queries instead of using the subquery:

    http://www.baldyweb.com/LastValue.htm

    Access is trying to "help" you, and as is sometimes the case it messes it up. I've seen it do this to subqueries before.

    By the way, you don't have separate tables for each course, do you?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Yea, I have seperate tables for each course because some students may not be enrolled in every course.

  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,640
    That is a normalization mistake IMO. How would you determine which courses I have taken?

    You have a situation for a classic many-to-many junction table (a course can be taken by many students, a student can take many courses). I would have a single table with fields for student ID, course ID, date and grade. That would be in addition to a students table and a courses table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Thanks for your insight. I made the changes you suggested and this gave me a partial answer. What I would like is to be able to view the most recent grades for each student for each subject. What I have now is the most recent grade irregardless of what the subject is. Is it possible to acheive this?

    I have included the database for reference.
    Attached Files Attached Files

  6. #6
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Try this:

    Code:
    SELECT tbl_Combo.Name, tbl_Combo.Subject, Max(tbl_Combo.Score) AS MaxOfScore
    FROM tbl_Combo INNER JOIN qryMaxDate ON (tbl_Combo.Date = qryMaxDate.MaxDate) AND (tbl_Combo.Name = qryMaxDate.Name)
    GROUP BY tbl_Combo.Name, tbl_Combo.Subject;

  7. #7
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Fabulouso! Is there anyway I can append the dates to the scores as well?

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

Similar Threads

  1. Update query only working on some records
    By JackieEVSC in forum Queries
    Replies: 3
    Last Post: 11-21-2011, 10:31 AM
  2. Update query not updating records
    By toer121 in forum Queries
    Replies: 1
    Last Post: 08-25-2011, 07:08 AM
  3. Update query for numbering the records
    By kumar.dkr in forum Queries
    Replies: 4
    Last Post: 11-24-2010, 06:06 AM
  4. Update query for ID #s to link records
    By fspswen in forum Queries
    Replies: 0
    Last Post: 11-20-2009, 01:52 PM
  5. Return records not updated by update query
    By ars80 in forum Queries
    Replies: 2
    Last Post: 05-01-2006, 09:23 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