title: SQL query for extract the highest value at a given time range?
body: <p>I have a problem on a sql query. I need to take the last 30 days and then remove only the 4 results with the "voting" value greater</p>
  
  <p>db structure</p>
  
  <pre><code>Id |    time    | voting
  1  | unix time  | 3
  2  | unix time  | 2
  3  | unix time  | 4
  4  | unix time  | 1
  5  | unix time  | 6
  </code></pre>
  
  <p>I would like to take me only the data of: 5-3-1-2</p>
  
  <p>I have tried with</p>
  
  <pre><code>select a.* 
  from table a 
  inner join 
      ( select votingng, max(time) as latest from table group by voting) v 
          on a.time = v.latest 
          and a.voting = v.voting 
  order by time desc limit
  </code></pre>