title: MySQL users table: find rows that have the same email address
body: <p>I have a users table in MySQL. </p>
  
  <pre><code>id | username | email
  </code></pre>
  
  <p>I would like to get the IDs of duplicated users based on the email address. So basically find the Ids of users where the email address can be found more than 1 times in the table.</p>
  
  <p>I wrote something like this:</p>
  
  <pre><code>SELECT id
  FROM users as users
  WHERE (
    SELECT count(id)
    FROM users as users2
    WHERE users.email = users2.email
  ) &gt; 1
  </code></pre>
  
  <p>It works ok, but very slow, as the query doesn't seem to use the index. Any other ideas? Thanks!</p>