codeigniter mysql left join include select

前端 未结 2 613
南方客
南方客 2021-01-03 14:28

How to convert the left join include select to codeigniter sql method? Thanks. I just want to know.

SELECT c1.c1_id, c1.c1_name, c2.c2_id, c2.c2_name, c2.c2_         


        
2条回答
  •  走了就别回头了
    2021-01-03 15:19

    $query='SELECT c1.c1_id, c1.c1_name, c2.c2_id, c2.c2_name, c2.c2_type, c2.c2_status, f.f_id, f.f_name, f2.f2_id, f2.f2_name FROM category2 c2 
    LEFT JOIN category1 c1 ON c1.c1_id = c2.c1_id 
    LEFT JOIN (
        SELECT DISTINCT c2_id, f_id, f_name FROM file ORDER BY f_id DESC
    ) f ON f.c2_id = c2.c2_id
    LEFT JOIN (
        SELECT DISTINCT c2_id, f2_id, f2_name FROM file2 ORDER BY f2_id DESC
    ) f2 ON f2.c2_id = c2.c2_id
    WHERE c2.c2_status = ?
    GROUP BY c2.c2_id';
    $params=array();
    $params[]=1;
    $result=$this->db->query($query,$params);
    $result=$result->result_array();
    print_r($result); 
    

    I would avoid using Codeigniter's Active Record class unless your goal is to obfuscate your code.

    "Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live."

提交回复
热议问题