title: Rails where condition with nil value
body: <p>I found out that using where with symbol :my_id => nil and using old school one with ? is different. Could anyone explain me why?</p>
  
  <pre><code>MyTable.where("my_id = ? ", nil).first
  SELECT `my_tables`.* FROM `my_tables` WHERE (my_id = NULL ) LIMIT 1
  </code></pre>
  
  <p>Does not get any data</p>
  
  <pre><code>MyTable.where(:my_id =&gt; nil).first
  SELECT `my_tables`.* FROM `my_tables` WHERE (`my_tables`.`my_id` IS NULL) LIMIT 1
  </code></pre>
  
  <p>Get data which has my_id is null.</p>
  
  <p>What is the best practise to use in rails?</p>
  
  <p>I think I didn't make clear about my question.
  In my rails application, request parameter is nil. 
  Existing coding is MyTable.where(:my_id => params[:id]).first
  In table, there are lots of records which have my_id is null.
  Therefore, the first record from table is pick up without realizing. 
  First of all, yes it is the problem with unclean data in table.</p>
  
  <p>To solve this problem.
  I find two solutions</p>
  
  <p>Solution 1</p>
  
  <pre><code>if params[:id].present?
    MyTable.where(:my_id =&gt; params[:id]).first
  end
  </code></pre>
  
  <p>Solution 2</p>
  
  <pre><code>MyTable.where("my_id = ? ", nil).first
  </code></pre>
  
  <p>As you know, if we put (if condition more and more), our application will get slower and it will not be functional programming.
  When I try solution 2, I get surprised because I am expecting it should give same result.</p>