SQL queries with AND/OR conditions I'm transferring SQL statements from a Drupal 5 installation to Drupal 8, and struggling with And/Or condtions. eg given the original SQL:

    SELECT .....
    WHERE .....
          AND classes.description = "Photographer"
          AND (classoptions.description = "Name of photographer here"
           OR classoptions.description = "Not assigned").


I've translated it to:

$query = $this-&gt;dbConnection-&gt;select('classes');
....etc....
$query-&gt;condition('classes.description', 'Photographer');


So far, so good. Then I need an OR condition for

$query-&gt;condition('classoptions.description', 'Name of photographer here');
$query-&gt;condition('classoptions.description', 'Not assigned');


Looking at documentation on-line, using db_or() is suggested, as in :

$query-&gt;condition(db_or()
 -&gt;condition('classoptions.description', 'Name of photographer here');
 -&gt;condition('classoptions.description', 'Not assigned'));


..but this is a) deprecated, b) gives error 'db_or function not found'
The replacement for db_or() is to obtain a new Condition object, but what am I supposed to do with it?  The function  

 $query-&gt;orConditionGroup();


Will return a new Condition object, and the code

$query-&gt;condition(orConditionGroup()
 -&gt;condition('classoptions.description', 'Name of photographer here');
 -&gt;condition('classoptions.description', 'Not assigned'));


Formats a Condition object with the conditions to be ORed just fine.But again, how do I incorporate this into the query?
Have a look how orConditionGroup() is used in core.
For example, in ConfigEntityQueryTest it is used this way:

$query = $this-&gt;factory-&gt;get('config_query_test', 'AND');
$and_condition_1 = $query-&gt;orConditionGroup()
  -&gt;condition('id', '2')
  -&gt;condition('label', $this-&gt;entities[0]-&gt;label);
$and_condition_2 = $query-&gt;orConditionGroup()
  -&gt;condition('id', 1)
  -&gt;condition('label', $this-&gt;entities[3]-&gt;label);
$this-&gt;queryResults = $query
  -&gt;condition($and_condition_1)
  -&gt;condition($and_condition_2)
  -&gt;execute();


I am sure you can apply this to your problem.