title: MySQL CONCAT: how to add data at the end of string and delete data at the beginning if size exceeded?
body: <p>unfortunately I have not found anything yet, maybe anyone could help me or give me a hint?</p>
  
  <p>I have a table called "users" and a field "last_login" where I want to store the login dates of the last let's say 30 logins. So, each time the user logs in successfully, the timestamp should be added at the end of the string, so it looks sth like this:</p>
  
  <blockquote>
    <p>logdindate1;logindate2;logindate3;...</p>
  </blockquote>
  
  <p>..whereas logindates are timestamps with a certain size. However, if we reach logindate31, logindate1 should be deleted and logindate31 added at the end.</p>
  
  <p>Is there any way to do that very easily within the MySQL query or do I have to check length with php? If yes, will I need a SELECT, then check the length, cut it and then a separate UPDATE? Or is there any better way to do it at all?</p>
  
  <p>The query I have till now is (it does not check the length or cut anything):</p>
  
  <pre><code>&lt;?php $query = "UPDATE user SET login_date = CONCAT(login_date,'".$logindate.";') WHERE id='".$user_id."';"; ?&gt;
  </code></pre>
  
  <p>Thank you very much in advance!</p>