title: How to move data one table to another table older than 30 days record?
body: <p>I am developing chat apps.</p>
  
  <p>I have two table <code>messages</code> and <code>message_archives</code> both table column is same.</p>
  
  <p>My <code>messages</code> table containing 1,00,000 record. I want to move record to <code>message_archives</code> from messages those are older than 30 days.</p>
  
  <p>My Code:</p>
  
  <pre><code>$privateMsg = mysql_query("SELECT * FROM messages WHERE created &lt; DATE_SUB(curdate(), INTERVAL 30 DAY)");
  if(mysql_num_rows($privateMsg)){
      while($getPrivateMsg=mysql_fetch_array($privateMsg)){
          mysql_query("INSERT INTO message_archives SET user_id='".$getPrivateMsg['user_id']."', friend_id='".$getPrivateMsg['user_id']."', message='".$getPrivateMsg['message']."', is_view='0', created='".$getPrivateMsg['created']."'");
  
          mysql_query("DELETE FROM messages WHERE id='".$getPrivateMsg['id']."'");
      }
      echo "Message move to archives older than 30 days";
  }else{
      echo "Error!! message not moved!!!.";
  }
  </code></pre>
  
  <p>Above code working perfectly. But i need to customize my code. I need it in single query. Is there any shortcut way to single query?</p>