Nested OR and AND condition with db_select How can I convert the following query with db_select 

SELECT *
FROM 'my_table'
WHERE
(condition1 &lt; "value1" AND ((conidition2 &gt; "value2") OR (condition3 &lt; "value3")))
  OR
(condition4 &lt; "value5" AND ((condition6 &lt; "value6") OR (condition7 &lt; "value7")))


I am trying with

$query = db_select('mytable');

$query-&gt;condition(
          db_and()-&gt;condition("condition1","value1")
                 -&gt;condition(
                             db_or()-&gt;condition("condition2","value2")-&gt;condition("condition3","value3")
                             ));
$query-&gt;condition(
          db_and()-&gt;condition("condition4","value4")
                 -&gt;condition(
                             db_or()-&gt;condition("condition5","value5")-&gt;condition("condition6","value6")
                             ));

  $query_debugg = $query-&gt;__toString();
dpm($query_debugg);


issue is with the "AND" in between where is should be "OR", it is expected I know.how can I change it

Output String

SELECT 
FROM 
{mytable} mytable
WHERE ( (condition1 = :db_condition_placeholder_0) AND( (condition2 = :db_condition_placeholder_1) OR (condition3 = :db_condition_placeholder_2) ))AND( (condition4 = :db_condition_placeholder_3) AND( (condition5 = :db_condition_placeholder_4) OR (condition6 = :db_condition_placeholder_5) ))
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.