title: sql query | handling multiple where conditions with a potential null value
body: <p>Assume the following table:</p>
  
  <pre><code>╔═══╦══════════════╦═════════════╗
  ║   ║Property A    ║Property B   ║
  ╠═══╬══════════════╬═════════════╣
  ║ 1 ║ slow         ║low          ║
  ║ 2 ║ fast         ║high         ║
  ╚═══╩══════════════╩═════════════╝
  </code></pre>
  
  <p>User has the option to filter result using either both properties or just one. The input is stored in variables <code>$p1, $p2</code></p>
  
  <p>If both the variables get a value from user I can easily query them like this:</p>
  
  <pre><code>select * from table where (propertyA=$p1 and propertyB=$p2)
  </code></pre>
  
  <p>However if one of them gets no value from user, how do I query?
  Since the line in the above query <code>propertyA=$p1</code> would become false since <code>$p1</code> could be null, however the query result should return based on the value of <code>$p2</code>.</p>
  
  <p>For example for the input (null,low) the query should return the first record, but with my query, it will not.</p>
  
  <p>This example is just for two properties, I have multiple properties in my table so implementing multiple if conditions would be a hassle.</p>
  
  <p>I was wondering if there is any concise way to go about this.</p>
  
  <p>Thank you!</p>