title: MySQL - Group by duplicated value in table to do count and save output in another table
body: <p>I have a MySQL table called table1 which holds values of devices that are on a page. The page pings back a script EVERY 2 SECOND that fills out the table.</p>
  
  <p>The table structure is as follows:</p>
  
  <pre><code>id
  timestamp
  domain
  ip 
  useragent
  </code></pre>
  
  <p>Every device has a unique IP address. In the table, I have multiple entries belonging to the same device.</p>
  
  <p>I want to be able to count the number of records grouped by IP address and save this in a new table (called table2) which has the following structure:</p>
  
  <pre><code>id
  ip
  domain
  useragent
  count
  </code></pre>
  
  <p>In both table1 and table 2, id is auto-increment.</p>
  
  <p>So far, I have come up with:</p>
  
  <pre><code>SELECT   ip, COUNT(*) FROM table1 GROUP BY ip; HAVING COUNT(*) &gt; 1
  </code></pre>
  
  <p>How do I save the output into table2?</p>