title: How to conditionally SELECT multiple columns with MySQL?
body: <p>Suppose I have 3 columns to choose from: <code>colA</code>, <code>colB</code> and <code>colC</code>.</p>
  
  <p>We have 7 possibilities to SELECT from:</p>
  
  <pre><code>single column: colA | colB | colC
  double column: colA colB  | colA colC | colB colC
  triple column: colA colB colC
  </code></pre>
  
  <hr>
  
  <p>I would like to make a query that enables me to pick which columns I want to SELECT. For instance, if I want to pick columns <code>colB</code> and <code>colC</code>, then the SELECT should return</p>
  
  <pre><code>colB colC
  ---------
   1    4
   2    5
   3    6
  ---------
  </code></pre>
  
  <hr>
  
  <p>I already searched for quite some time, and what I encounter most are the <code>CASE</code> and <code>IF</code> <a href="http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html" rel="nofollow">Control Flow Functions</a>, but I could not achieve what it's described with them. For example, if I make the following query, the columns that are not activated show up with NULL values (whereas they should not show up):</p>
  
  <pre><code>SET @colB_switch := 1;
  SET @colC_switch := 0;
  
  SELECT
      CASE WHEN @colB_switch = 1 THEN colB END,
      CASE WHEN @colC_switch = 1 THEN colC END
  FROM my_table
  </code></pre>
  
  <hr>
  
  <p>For this simple case, I could simple hard code every single possibility, but when we have dozens of columns we have literally thousands of possibilities!</p>
  
  <p>PS: another approach would be pick which columns to <em>not</em> show up, maybe it's easier?</p>