1.查询的条件按mysql的语法顺序编码,相同的操作放一起
2.要查询的字段写明白。尽量少用或不用*;
----------------------------------------------
参照mysql 语法
select field1,field2 from table where 1 group by field1 order by field2 asc limit 5;
CI写法(Active Record 模式):
$this->db->select('tabl1.f1,tabl1.f2');
$this->db->select('table2.f3,table2.f4');
$this->db->join('table2', 'table2.id = tabl1.id','left');
$this->db->where(array("table2.f1"=>"xxx"));
$this->db->order_by('tabl1.f1','asc');
$this->db->group_by('table2.f2');
$this->db->limit(5);
$this->db->get('tabl1');