我有一个类似下面的“重复查询”
$qry = db_select('table1', 't1');
$qry->addField('t1','etid','entity_id');
$qry->join('node', 'n FORCE INDEX(field1)', 'n.nid = t1.etid');
$qry->join('table2','t2','n.nid = t2.entity_id');
$qry->join('table3','t3','t3.sid=t2.field2');
$qry->condition('t3.field', 'yes', '=');
$qry->condition('n.field', '<value>', 'LIKE');
$qry->condition('t1.field', '<id>', '=');
$qry->condition('n.field', '<value>', '=');
$qry->condition('n.field', <value>, '=');
$qry->condition('t1.field', '<vlaue>', '=');
$qry->orderBy('t1.field','DESC');
$qry->range(0,300);
我想为此查询添加一个OR
条件。因此它将是一个全局OR
条件。
我添加了如下代码
$or = db_or();
$or->condition('t1.field', [123,456], 'IN');
$qry->condition($or);
但是它没有添加OR
条件,而是将条件查询放在AND
条件中的括号内。
如何实现类似的输出查询
where field = value and field = value and field = value OR field = value
使用Drupal查询构建器?请帮助
答案 0 :(得分:1)
$db_and = db_and();
$qry = db_select('table1', 't1');
$qry->addField('t1','etid','entity_id');
$qry->join('node', 'n FORCE INDEX(field1)', 'n.nid = t1.etid');
$qry->join('table2','t2','n.nid = t2.entity_id');
$qry->join('table3','t3','t3.sid=t2.field2');
$db_and->condition('t3.field', 'yes', '=');
$db_and->condition('n.field', '<value>', 'LIKE');
$db_and->condition('t1.field', '<id>', '=');
$db_and->condition('n.field', '<value>', '=');
$db_and->condition('n.field', <value>, '=');
$db_and->condition('t1.field', '<vlaue>', '=');
$or = db_or();
$or->condition('t1.field', [123,456], 'IN');
$or->condition($db_and);
$qry->condition($or);
$qry->orderBy('t1.field','DESC');
$qry->range(0,300);