Whats is the right way to check for new messages?
SELECT * FROM mails
    WHERE user_id = 1
      AND sequence &gt; $left_off
    ORDER BY sequence
    LIMIT 100;


You need a column sequence that is monotonically increasing.  And AJAX needs to keep track of "where it left off".