Nested OR and AND condition with db_select
In Drupal, conditions are AND by default. It's easier to use objects directly, in my opinion:

$left_condition = new DatabaseCondition('AND');
$left_condition-&gt;condition( ... ); // add what you need

$right_condition = new DatabaseCondition('AND');
$right_condition-&gt;condition( ... ); // add what you need

$condition = new DatabaseCondition('OR');
$condition-&gt;condition($left_condition);
$condition-&gt;condition($right_condition);


But you can use db_and() and db_or() if you prefer.