title: WHERE-clause for last non-null value
body: <p>I'm making a community database for a school project and have ran into an issue. I am attempting to integrate a log system but retrieve the latest non-null value from column in a table called logs and present that information on a different page. My current code (without any attempt at filtering by their rank) looks as follows:</p>
  <pre><code>SELECT m.MemberID, m.MemberName, o.OfficeID, o.OfficeDesignation, p.PositionAbbreviation, l.LogRank
  FROM logs l
  INNER JOIN (SELECT l.LogMember, MAX(l.LogDate) AS maxLogDate FROM logs l GROUP BY l.LogMember) l2
      ON (l.LogMember = l2.LogMember AND l.LogDate = l2.maxLogDate)
  INNER JOIN members m
      ON (l.LogMember = m.MemberID)
  INNER JOIN offices o
      ON (l.LogOffice = o.OfficeID)
  INNER JOIN positions p
      ON (l.LogPosition = p.PositionID)
  GROUP BY m.MemberID;
  </code></pre>
  <p>The above query returns the latest entry for each member in the logs table, but I can't figure out how to, when l.LogRank returns NULL, take the latest non-null value only for that column.</p>
  <p>I have struggled with a variety of approaches to this problem over the past week to no avail. Any help/pointers would be appreciated.</p>
  <p>EDIT: Sample data seen below:</p>
  <pre><code>+-------+-----------+---------+-----------+-------------+-----------+
  | LogID | LogMember | LogRank | LogOffice | LogPosition |  LogDate  |
  +-------+-----------+---------+-----------+-------------+-----------+
  |   1   |     1     |    1    |     7     |      5      | TIMESTAMP |
  +-------+-----------+---------+-----------+-------------+-----------+
  |   2   |     1     |    1    |           |      1      | TIMESTAMP |
  +-------+-----------+---------+-----------+-------------+-----------+
  |   3   |     1     |         |     1     |             | TIMESTAMP |
  +-------+-----------+---------+-----------+-------------+-----------+
  </code></pre>
  <p>The various INT values reference IDs in the relevant other tables.</p>
  <p>Desired Output:</p>
  <pre><code>+-------+-----------+---------+-------------------+-----------------+-----------+
  | LogID | LogMember | LogRank | OfficeDesignation | PositionAbbrev. |  LogDate  |
  +-------+-----------+---------+-------------------+-----------------+-----------+
  |   1   |     1     |    1    |        C-6        |        CO       | TIMESTAMP |
  +-------+-----------+---------+-------------------+-----------------+-----------+
  </code></pre>
  <p>So basically I want to retrieve the MemberID, MemberName, OfficeID, OfficeDesignation, PositionAbbreviation, and LogRank from a variety of tables and get the latest non-null record for each column.</p>