title: Self join table current row and next row horizontally in MySQL
body: <p>I am implementing a functionality wherein I have to delete current row based on values present in next row of same table.</p>
  
  <p>I have records with columns: <code>id</code>, <code>created_at</code> and <code>mark</code>.</p>
  
  <p>I need delete all records,</p>
  
  <pre><code>WHERE currentrow.mark != nextrow.mark or (currentrow.mark = nextrow.mark and currentrow.created_at= '2000-01-01 00:00:00.000')
  </code></pre>
  
  <p>i.e. only records with next rows have not same mark or records with next row have same mark and <code>created_at = '2000-01-01 00:00:00.000'</code></p>
  
  <pre><code>id      created_at                  mark
  235    1990-01-01 00:00:00.000      5                  /delete
  236    1990-01-01 00:00:00.000      5                  /delete
  237    1990-01-01 00:00:00.000      5
  238    2016-10-10 23:45:40.000      5
  
  
  id       created_at                 mark
  312    1990-01-01 00:00:00.000      8                  /delete
  313    2016-01-09 18:00:00.000      6                  
  314    1990-01-01 00:00:00.000      4                  /delete
  315    1990-01-01 00:00:00.000      7
  316    2016-10-10 23:45:40.000      7
  </code></pre>
  
  <p>Kindly help to retrieve table every row joined next rows of same table horizontally in result set.</p>