skip to Main Content

Any idea how to convert query below into Codeigniter?

select agency from agency where agency not in (SELECT agency FROM trip where trip_type = 'local trip' group by trip_type, agency having count(agency)=(select count(*) from role));

Tried but failed. Please help

2

Answers


  1. Chosen as BEST ANSWER

    I got the idea from codeigniter select

    $db = ConfigDatabase::connect();    
    $trip_type = $this->request->getVar('trip_type');
    
    $query = $db->query("select agency from agency where agency not in (SELECT agency FROM trip where trip_type = '".$trip_type."' group by trip_type, agency having count(agency)=(select count(*) from role));");
    
    $results = $query->getResultArray();
    

  2. $this->db->select('agency');
    $this->db->from('agency');
    $this->db->where_not_in('agency', function($query) {
    $query->select('agency')->from('trip')->where('trip_type', 'local trip')->group_by(['trip_type', 'agency'])->having('count(agency)', '(SELECT count(*) FROM role)', FALSE);
    }, NULL, FALSE);
    $query = $this->db->get();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search