title: "Totals" Query: show last non-blank string
body: <p>I have a totals query (one where I clicked the totals button, and it has "group by" columns) in Access 2007. Most of the columns are fine... group by columns, max columns, min columns, etc. For some of them though, I want to extract only the last non-blank (not "" or null) value of a string column.</p>
  
  <p>Here's a sample of what my SQL looks like:</p>
  
  <pre><code>SELECT  Min(Duplicates.AttendedODBefore) AS AttendedODBefore,
          Min(Duplicates.ContactByPost) As ContactByPost,
          Last(Duplicates.PlannedStart) As PlannedStart,
          Min(Duplicates.AccessibilityRequirements) AS AccessibilityRequirements,
          Last(Duplicates.UcasNumber) As UcasNumber
  --      ^^^^
  FROM    DuplicateStudents As Duplicates
  GROUP BY
          Duplicates.ID
  </code></pre>
  
  <p>The expression highlighted is the one I want changing to the last non-blank field. Is there an Access-specific or plain SQL expression which will do this?</p>
  
  <p><strong>Edit:</strong> Turns out that <code>Min()</code> and <code>Max()</code> work on string values and ignores null values, taking the first and last values alphabetically. It's not perfect, because it doesn't guarantee that the value selected is the last one, but it's better than just a load of nulls which is what using <code>Last()</code> might give.</p>