How do I reproduce this SQL with Drupal 7's query builder? SELECT * FROM mytable
WHERE ('myfield1' = 'someval1' AND 'myfield2' = 'someval1')
   OR ('myfield1' = 'someval2' AND 'myfield2' = 'someval2')
   OR ('myfield1' = 'someval3' AND 'myfield2' = 'someval3')


I'm trying to do this with a foreach() loop:

foreach($mywords as $w)
{
  $myquery
    -&gt;condition('myfield1', $w)
    -&gt;condition('myfield2', $w);
}


Each iteration of the loop, however, should add the next set of conditions.
You need to do something like this:

$query = db_select('mytable', t)-&gt;fields('t');
$condition = db_or();
foreach($mywords as $w {
  $condition-&gt;condition(db_and()-&gt;condition('myfield1', $w)-&gt;condition('myfield2', $w));
}
$result = $query-&gt;condition($condition)-&gt;execute();


This is not tested but should work.

For reference, see db_or and db_and