title: Simulate LAG with GROUP BY in MySQL 5.6
body: <p>How do I simulate LAG function from MySQL 8.0 in MySQL 5.6 where I get the previous info with same ItemID. I've created this illustration to simulate the table and the output of the query I need. The gray data is the original table and the orange is the data from the previous row with same ItemID and the closest previous date.</p>
  
  <p><a href="https://i.stack.imgur.com/oqycQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oqycQ.png" alt="enter image description here"></a></p>
  
  <p>I've tried joining the table with it self on A.ItemID = B.ItemID AND B.Date &lt; A.Date. I've also tried group by ItemID and tried getting the max date below the current date.</p>
  
  <p>I've tried this aswell. </p>
  
  <pre><code>SET @lag = -1;
  SELECT *, @lag PreviousInfo, @lag:=Info CurrentInfo FROM Table1
  </code></pre>
  
  <p>However this always just returns the info from the previous row and is not grouped by the ItemID.</p>