title: Best practices for filtering data
body: <p>The way I see it, when building dynamic charts with filters, each time the user requests filtered data I can</p>
  
  <ol>
  <li><p>Execute a new MySQL query, and use MySQL to do the filtering.</p>
  
  <pre><code>SELECT date,
    SUM(IF( `column` = `condition`, 1, 0)) as count
    ...
  </code></pre></li>
  <li><p>Execute a new MySQL query, and use the server-side language (PHP in my case) to filter.</p>
  
  <pre><code>function getData(condition)  {
    $resultSet = mysqli_query($link, "SELECT date, column ... ");
  
    $count = 0;
    while ($row = mysqli_fetch_assoc($result_set)) {
        if ($row['column'] == 'condition') {
            $count++;
        }
    }
  }
  </code></pre></li>
  <li><p>Initially execute a single MySQL query, pass all the data to the client, and use Javascript &amp; d3 to do the filtering.</p></li>
  </ol>
  
  <p>I expect the answer is not black-and-white. For instance, if some filter is barely requested, it may not make sense to make the other 95% of users wait for the relevant data, and thus the filter would necessitate a new data call. But I'm really thinking about edge cases - situations where filters are used regularly, but idiosyncratically. At times like this, is it better to put filtering logic in front-end, back-end, or within my database queries?</p>