title: Find columns with empty value in all rows of a table
body: <p>i'm searching for an SQL request which gives me all columns in a table that are never populated.</p>
  
  <p>For example, in a table like this one :</p>
  
  <pre>column 1 | column 2 | column 3 | column 4 | column 5
  ---------+----------+----------+----------+---------
  value    | NULL     | value    | value    | NULL
  NULL     | NULL     | value    | value    | NULL
  value    | NULL     | value    | NULL     | NULL
  value    | NULL     | value    | value    | NULL</pre>
  
  <p>The request will return : <pre>column 2, column 5</pre></p>
  
  <h3>EDIT :</h3>
  
  <p>I've created this little PHP script to generate the query and print the result :</p>
  
  <pre><code>$columns = $sql-&gt;select("SELECT column_name FROM information_schema.COLUMNS WHERE TABLE_NAME='table_name'");
  
  $query = "SELECT ";
  foreach($columns as $column) {
      $query .= "case when count(".$column[0].") = 0 then '".$column[0]."' end, ";
  }
  $query = substr($query, 0,-2);
  $query .= " FROM table_name";
  
  var_dump($sql-&gt;select($query));
  </code></pre>