title: Query the most recent timestamp (MAX/Last) for a specific key, in Influx
body: <p>Using InfluxDB (v1.1), I have the requirement where I want to get the last entry timestamp for a specific key. Regardless of which measurement this is stored and regardless of which value this was.</p>
  
  <p>The setup is simple, where I have three measurements: <code>location</code>, <code>network</code> and <code>usage</code>.<br>
  There is only one key: <code>device_id</code>. </p>
  
  <p>In pseudo-code, this would be something like:</p>
  
  <pre><code># notice the lack of a FROM clause on measurement here...
  SELECT MAX(time) WHERE 'device_id' = 'x';
  </code></pre>
  
  <p><strong>The question:</strong> What would be the most efficient way of querying this?</p>
  
  <p>The reason why I want this is that there will be a decentralised sync process. Some devices may have been updated in the last hour, whilst others haven't been updated in months. Being able to get a distinct "last updated on" timestamp for a device (key) would allow me to more efficiently store new points to Influx.</p>
  
  <p>I've also noticed there is a similar discussion on <a href="https://github.com/influxdata/influxdb/issues/5793" rel="noreferrer">InfluxDB's GitHub repo (#5793)</a>, but the question there is not filtering by any field/key. And this is exactly what I want: getting the 'last' entry for a specific key.</p>