View Full Version : Including null values when using MAX function


sarahs
06-07-2002, 03:25 PM
I looked up this topic in the discussion forum and followed somebody's advice for setting up two queries to return records with the most recent date.

I have a table called Workers [Primary Key = WorkerID]

and a table called [Worker Assessment], Primary Key = AssessmentID.

Each worker can have many assessments, or no assessment at all. I want a query to return the most recent assessment for all workers who have one, plus some standard value ["Null" or "Unasessed" or "0"] for all workers who have no assessment.

I have:

Query 1: [Set ARecent]

SELECT Max([Worker Assessment].[Assessment Date]) AS MaxDate, [Worker Assessment].WorkerID

FROM [Worker Assessment]

GROUP BY [Worker Assessment].WorkerID;

and Query 2: [GetARecent]

SELECT [SetARecent].WorkerID, [SetARecent].MaxDate, [Worker Assessment].Assessment

FROM [SetARecent]

INNER JOIN [Worker Assessment] ON [SetARecent].WorkerID = [Worker Assessment].WorkerID;

The problem is that this returns only records with at least one Assessment, and eliminates about half the records I am trying to find.

What can I do to include null values?

Pat Hartman
06-07-2002, 08:53 PM
Use a RIGHT JOIN rather than an INNER JOIN.