title: Selecting most recent result when NULL (MySQL)
body: <p>I've got three tables with a fairly odd relationship with each other, and I'm trying to get some data out of them but not figuring out a good way to do it. The three tables are basically:</p>
  
  <ul>
  <li>A has a one-to-many relationship with B.</li>
  <li>B has a some-to-one relationship with C.</li>
  </ul>
  
  <p>The "A" table has information about an overarching scope. For the sake of argument, let's say that table A contains a list of jobs that you've had or something like that. <code>A.Id</code> is the primary key for A.</p>
  
  <p>The "B" table contains "spotlight" detalils about things relating to the "A" table. <code>B.Id</code> is the primary key for B, it has a <code>B.Timestamp</code> to indicate the time that the event happened, and it has a <code>B.AId</code> column to indicate which "A" it refers back to. </p>
  
  <p>This is where things get complicated. The "C" table contains information about things relating to <em>some</em> entries in "B". It has two columns, essentially <code>C.Bid</code> and <code>C.Value</code>. If you were to <code>SELECT * FROM A JOIN B ON B.AId = A.ID LEFT JOIN C ON C.Bid = B.Id</code>, you'd be left with something like this:</p>
  
  <pre><code>A.Id    B.Id    C.Value  (... and other columns, of course...)
     1       1         12
     1       2       NULL
     1       3       NULL
     1       4         13
     1       5       NULL
     2       6         91
     2       7         12
     2       8       NULL
     2       9       NULL
     2      10       NULL
     3      11         92
     3      12         91
     3      13       NULL
     3      14         92
  </code></pre>
  
  <p>etc...</p>
  
  <p>Now, I've got the timestamps in the "B" table that can help me get an understanding of when the <code>C.Value</code> changes,  but what if I wanted to see the expected value of <code>C.Value</code> when <code>B.Id</code> = 10? Based on the data in there, I <em>know</em> that the right answer is still <code>C.Value = 12</code> since it hasn't changed, but I have no good way of visualizing it.</p>
  
  <p>So, what I'm asking for, basically, is help to construct a query that can show me <code>A.Id, B.Id</code> and the <em>most recent non-null</em> <code>C.Value</code> using <code>B.Timestamp</code> as the criteria. The Ids can come out of order at times, but the Timestamp is always correct.</p>
  
  <p>Thanks!</p>