How to construct database query with conditions that include 'and' and 'or' clauses?
Here's an example, taken from statistics.pages.inc

$query = db_select('accesslog', 'a', array('target' =&gt; 'slave'))-&gt;extend('PagerDefault')-&gt;extend('TableSort');
$query-&gt;join('users', 'u', 'a.uid = u.uid');

$query
  -&gt;fields('a', array('aid', 'timestamp', 'url', 'uid'))
  -&gt;fields('u', array('name'))
   -&gt;condition(db_or()
    -&gt;condition('a.path', 'node/' . $node-&gt;nid)
    -&gt;condition('a.path', 'node/' . $node-&gt;nid . '/%', 'LIKE'))
  -&gt;limit(30)
  -&gt;orderByHeader($header);


What you want to notice, is the use of db_or(), which adds an OR to your query. There is also the similar db_and(). You can mix and match the two as much as you want. The db_and() documentation also has comments with examples of the two used together.