title: How can I detect redundant rows in the table?
body: <p>I'm following <strong>solution #1</strong> of <a href="https://security.stackexchange.com/questions/128468/why-not-have-an-identical-session-cookie-for-different-users-devices#128471">this answer</a>. After a while, there will be some redundant rows in the table. Suppose this table:</p>
  
  <pre><code>+------+------------------+
  | user |     cookie       |
  +------+------------------+
  | 1    | ojer0f934mf2...  |
  | 2    | ko4398f43043...  |
  | 2    | 34fjkg3j438t...  |
  | 3    | 0243hfd348i4...  |
  +------+------------------+
  </code></pre>
  
  <p>when user <code>1</code> removes his browser's cookies, still this row exists in the database:</p>
  
  <pre><code>| 1    | ojer0f934mf2...  |
  </code></pre>
  
  <p>And when he opens my website, he needs to log in again. So here is the table:</p>
  
  <pre><code>+------+------------------+
  | user |     cookie       |
  +------+------------------+
  | 1    | ojer0f934mf2...  | -- now this row is useless anymore
  | 2    | ko4398f43043...  |
  | 2    | 34fjkg3j438t...  |
  | 3    | 0243hfd348i4...  |
  | 1    | 0243hfd348i4...  |
  +------+------------------+
  </code></pre>
  
  <p>Surely in future, the number of such useless rows will increase. Well how can I manage it? Actually I can create an <code>EVENT</code> to clean that table up <em>(per day)</em> by removing redundant rows. But here is the problem: How can I detect them? How can I specify a row is useless?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> I can add a new column and store the timestamp, and then remove all old-timestamp rows by an <code>EVENT</code> <em>(or a cron jobs)</em>. But that isn't a perfect solution. I like a cookie be valid until user signs out <em>(so I don't like any limitation (or expire time) for cookies)</em>.</p>
  
  <p>Now I'm looking for a solution to determine redundant rows <em>(not old rows)</em>.</p>