title: Filter unique records from a database while removing double not-null values
body: <p>This is kind of hard to explain in words but here is an example of what I am trying to do in SQL. I have a query which returns the following records:</p>
  
  <pre><code>ID     Z
  ---   ---
  1      A
  1      &lt;null&gt;
  2      B
  2      E
  3      D
  4      &lt;null&gt;
  4      F
  5      &lt;null&gt;
  </code></pre>
  
  <p>I need to filter this query so that each unique record (based on ID) appears only once in the output and if there are multiple records for the same ID, the output should contain the record with the value of Z column being <strong>non-null</strong>. If there is only a single record for a given ID and it has value of null for column Z the output still should return that record.  So the output from the above query should look like this:</p>
  
  <pre><code>ID     Z
  ---   ---   
  1      A
  2      B
  2      E
  3      D
  4      F
  5      &lt;null&gt; 
  </code></pre>
  
  <p>How would you do this in SQL?</p>