title: mysql query: SELECT DISTINCT column1, GROUP BY column2
body: <p>Right now I have the following query:</p>
  
  <pre><code>SELECT name, COUNT(name), time, price, ip, SUM(price) 
    FROM tablename 
   WHERE time &gt;= $yesterday 
     AND time &lt;$today GROUP BY name
  </code></pre>
  
  <p>And what I'd like to do is add a DISTINCT by column 'ip', i.e.</p>
  
  <pre><code>SELECT DISTINCT ip FROM tablename 
  </code></pre>
  
  <p>So my final output would be all the columns, from all the rows that where time is today, grouped by name (with name count for each repeating name) and no duplicate ip addresses.</p>
  
  <p>What should my query look like? (or alternatively, how can I add the missing filter to the output with php)?</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p>[UPDATE] </p>
  
  <p>To minimize confusion, consider this (simplified) db table:</p>
  
  <pre><code>|   name   |   ip   |
  ---------------------
  |  mark    |  123   |
  |  mark    |  123   |
  |  mark    |  456   |
  |  dave    |  789   |
  |  dave    |  087   |
  </code></pre>
  
  <p>The result I'm looking for would be an HTML table looking like this:</p>
  
  <pre><code>|  name    |  name count   |
  ----------------------------
  |  mark    |      2        |
  |  dave    |      2        |
  </code></pre>
  
  <p>What I'm currently getting is:</p>
  
  <pre><code>|  name    |  name count   |
  ----------------------------
  |  mark    |      3        |
  |  dave    |      2        |
  </code></pre>
  
  <p>(it counts mark 3 times, even though two times are with the same ip).</p>