title: MySQL parameterized SELECT query with optional column filter
body: <p>I have a requirement to build a versatile parameterized <code>SELECT</code> query which fetches data from a mysql table and optionally filters that data by values from a column in one fell swoop.</p>
  
  <p>I know this can be achieved with mutltiple SELECTs, but it has to be just one statement.</p>
  
  <p>The query either fetches all data if a NULL is passed or fetches filtered data if a value is passed in other than NULL.</p>
  
  <p>One of the reasons for this requirement is we are externalizing our SQL strings.</p>
  
  <p>I have managed to come up with this:</p>
  
  <pre><code>SELECT * FROM `table` WHERE `column` =  COALESCE(NULLIF(?,''),`column`);
  </code></pre>
  
  <p>I pass in a <code>NULL</code> when I need to fetch unfiltered data and it works smoothly, efficiently.</p>
  
  <p>However, it never fetches data for which <code>**column**</code> is NULL.</p>
  
  <p>How do I make it fetch columns with NULL data? </p>