title: How can I speed up this SELECT CONCAT/GROUP BY query?
body: <p>I'm working on selecting locations (city, state) out of a database.  The problem is that the query is running a tad slow and I'm not sure how to speed it up.  For example:</p>
  
  <pre><code>SELECT CONCAT_WS(', ', city, state) as location, AVG(latitude), AVG(longitude) 
  FROM places
  WHERE city='New York' AND state='NY'
  GROUP BY location
  </code></pre>
  
  <p>There's going to be a CONCAT on the location regardless, because I want the database to return a pretty, concatenated version of the location (unless there's reason to do this in the code instead).  For example, "New York, NY".  In reality, a third column is sometimes thrown into the mix (zipcode).  I'm running on MySQL.</p>
  
  <p>What would be the best way to optimize this query?</p>
  
  <p>Also, as a secondary question, would adding "DISTINCT" slow down the query in any way?  For example:</p>
  
  <pre><code>SELECT DISTINCT CONCAT_WS(', ', city, state) as location, AVG(latitude), AVG(longitude) 
  FROM places
  WHERE city='New York' AND state='NY'
  GROUP BY location
  </code></pre>
  
  <p>(I'm currently doing this now, but in the process of asking this question, I realized that DISTINCT was not necessary due to the GROUP BY clause; however, since it is unnecessary I wonder if it makes any difference at all and if I should bother rocking the boat in order to speed up the query.)</p>
  
  <p>Edit: There's already an index on city, state and zipcode; plus their combinations therein (city, zipcode; and state/zipcode alone).</p>