Results 1 to 5 of 5
  1. #1
    rachello89 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    15

    Query return 0 for null values

    I have two tables: tblStudents and tblEnrollments. The query I have designed shows the StudentID and counts the number of Enrollments that each student has. I want the students who don't have any enrollments to still show up and have a 0 by their ID. Right now, only the students with enrollments show up in the query results.



    Here is my SQL Statement:

    SELECT tblStudents.StudentID, Count(tblEnrollments.EnrollmentID) AS CountOfEnrollmentID
    FROM tblStudents INNER JOIN tblEnrollments ON tblStudents.StudentID = tblEnrollments.StudentID
    GROUP BY tblStudents.StudentID;

    What do I need to do to it to have null values display as zero? Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You are probably going to want a Left Join and use the Nz() function.

  3. #3
    rachello89 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    15
    Thanks, that did it! I was trying to use the Nz() function before, but was unsuccessful. Changing to LEFT JOIN fixed it. BTW, what is the difference between LEFT JOIN and INNER JOIN?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Left Join returns *all* of the records from the "Left" table and records from the "Right" table where the criteria matches. Inner Join *only* returns records where the criteria matches from both tables.

  5. #5
    rachello89 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    15
    Thank you!

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

Similar Threads

  1. Query not returning null values
    By janelgirl in forum Access
    Replies: 5
    Last Post: 10-11-2011, 10:31 AM
  2. Query with null values
    By Psyclone in forum Queries
    Replies: 3
    Last Post: 03-30-2011, 09:57 PM
  3. No return on Null values
    By forrestapi in forum Queries
    Replies: 4
    Last Post: 10-18-2010, 08:09 AM
  4. Null Values in query
    By LesleaOH in forum Queries
    Replies: 0
    Last Post: 10-19-2009, 04:45 PM
  5. Null Values not showing up in a Query
    By Valli in forum Queries
    Replies: 0
    Last Post: 01-04-2006, 03:53 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