agroup 2 OR after和codeigniter

时间:2015-09-25 19:28:10

标签: sql codeigniter

问候!我对这个SQL查询有点问题,我需要加入几个" OR"在括号上..我不知道该怎么做..所以这就是例子:

SELECT a.a1, b.b1, c.c1 from a inner join b on a.a1=b.b1 inner join c on a.a1 = c.c1 where c.c2='t' and ( a.a1 like %XXXX% or b.b1 like %XXXX% )

这就是我在codeigniter代码上写的

$this->db->select("a.a1, b.b1, c.c1");
$this->db->where("c.c2",'t');
$this->db->like("a.a1", $match);
$this->db->or_like("b.b1", $match);
$this->db->join("b","a.a1 = b.b1",'inner');
$this->db->join("c","a.a1 =c.c1",'inner');

但这是输出,显然不是我想要的

SELECT a.a1, b.b1, c.c1 from a inner join b on a.a1=b.b1 inner join c on : a.a1 = c.c1 where c.c2='t' and a.a1 like %XXXX% or b.b1 like %XXXX%

1 个答案:

答案 0 :(得分:0)

$this->db->select("a.a1, b.b1, c.c1");
$this->db->where("c.c2",'t');
$this->db->group_start(); // (
$this->db->like("a.a1", $match);
$this->db->or_like("b.b1", $match);
$this->db->group_end(); // )
$this->db->join("b","a.a1 = b.b1",'inner');
$this->db->join("c","a.a1 =c.c1",'inner');