title: Optimize two COUNT/DISTINCT queries
body: <p>I have a table with column1 and column2 (both of them contain TEXT). I want to get:</p>
  
  <p>1) the count of unique rows of column1@table, case-insensitive</p>
  
  <p>2) the count of unique rows of column1@table and column2@table, case-insensitive</p>
  
  <pre><code>SELECT count(*) AS unique_row1 FROM (SELECT DISTINCT lower(column1) FROM table);
  
  SELECT count(*) AS unique_rows12 FROM (SELECT DISTINCT lower(column1),lower(column1) FROM table);
  </code></pre>
  
  <p>Is there a more efficient way to do it? Is there's a way to do it in a one query? I use SQLite3.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Edit (due to <a href="https://stackoverflow.com/a/8966403/974317">@ypercube's response</a>):</strong>
  Collation was default (case-sensitive, at least I didn't do <code>COLLATE NOCASE</code> anywhere).</p>
  
  <p>Also I've made a test and with <code>COLLATE NOCASE</code> it's quite faster and the numbers are the same:</p>
  
  <pre><code># time echo "SELECT count(DISTINCT lower(column1)), count(DISTINCT lower(column1 || column2)) FROM table;" | sqlite3 db.sqlite3
  1643|5997
  echo   0.00s user 0.00s system 25% cpu 0.003 total
  sqlite3 db.sqlite3  0.58s user 0.04s system 96% cpu 0.643 total
  
  # time echo "SELECT count(DISTINCT column1), count(DISTINCT column1 || column2) FROM table;" | sqlite3 db.sqlite3              
  1658|6199
  echo   0.00s user 0.00s system 36% cpu 0.002 total
  sqlite3 db.sqlite3  0.42s user 0.04s system 95% cpu 0.483 total
  
  # time echo "SELECT count(DISTINCT column1 COLLATE NOCASE), count(DISTINCT (column1 || column2) COLLATE NOCASE) FROM table;" | sqlite3 db.sqlite3
  1643|5997
  echo   0.00s user 0.00s system 32% cpu 0.002 total
  sqlite3 db.sqlite3  0.43s user 0.04s system 98% cpu 0.481 total
  </code></pre>
  
  <p><code>COUNT(DISTINCT column1, column2)</code> shows an error though: <code>wrong number of arguments to function count()</code>, but I hope I've got your idea.</p>