title: MySQL select records using MAX(datefield) minus three days
body: <p>Clearly, I am missing the forest for the trees...I am missing something obvious here!</p>
  
  <p>Scenario:</p>
  
  <p>I've a typical table <code>asset_locator</code> with multiple fields:</p>
  
  <pre><code>id, int(11) PRIMARY
  logref, int(11)
  unitno, int(11)
  tunits, int(11)
  operator, varchar(24)
  lineid, varchar(24)
  uniqueid, varchar(64)
  timestamp, timestamp
  </code></pre>
  
  <hr>
  
  <p>My current challenge is to SELECT records from this table based on a date range. More specifically, a date range using the MAX(timestamp) field. 
  So...when selecting I need to start with the latest timestamp value and go back 3 days. </p>
  
  <p>EX: I select all records WHERE the <code>lineid</code> = 'xyz' and going back 3 days from the latest timestamp. Below is an actual example (of the dozens) I've been trying to run. 
  MySQL returns a single row with all NULL values for the following: </p>
  
  <pre><code>SELECT id, logref, unitno, tunits, operator, lineid, 
          uniqueid, timestamp, MAX( timestamp ) AS maxdate
  FROM asset_locator 
  WHERE 'maxdate' &lt; DATE_ADD('maxdate',INTERVAL -3 DAY)
  ORDER BY uniqueid DESC
  </code></pre>
  
  <p>There MUST be something obvious I am missing. If anyone has any ideas, please share. 
  Many thanks!</p>