databaseの接続設定は済んでいる前提 $subQuery = $this->db->select('count(*) as column_count, sample_id')->get_compiled_select('table_a'); $this->db->select('*')->join("({$subQuery}) AS table_a", 'table_a.sample_id = samples.id', 'left', false); $query = $this->db->get('samples'); get() ではなく、get_compiled_select() …