title: CodeIgniter 4 Inner Join in Codeigniter
body: <p>Just want to ask if how can I use the INNER JOIN function on CodeIgniter 4? I'm trying to convert the SQL statement below to CodeIgniter 4 but since I'm just new in this area, I find it diffucult.</p>
  <pre><code>SELECT l.l_id, u.fname, u.mname, u.lname, u.dept, u.user_type, u.u_grdsec, e.e_name, l.date_added, DATE(l.date_added), date_format(l.date_added, '%H:%i') as 'time'
  FROM logs l INNER JOIN users u ON l.u_id = u.u_id
  INNER JOIN establishment e ON l.e_id = e.e_id
  WHERE DATE(l.date_added) = '$rep_date'
  GROUP BY
     date_format(l.date_added, '%H:%i'), l.u_id
  ORDER BY l.date_added ASC&quot;;
  </code></pre>
  <p>As I researched, I find this way. However, I didn't know how can I put the WHERE, GROUP BY and ORDER by clause in there.</p>
  <pre><code>$builder = $this-&gt;db-&gt;table(&quot;logs as l&quot;);
  $builder-&gt;select('l.l_id, u.fname, u.mname, u.lname, u.dept, u.user_type, u.u_grdsec, e.e_name, l.date_added, DATE(l.date_added), date_format(l.date_added, &quot;%H:%i&quot;) as &quot;time&quot;');
  $builder-&gt;join('users as u', 'l.u_id = u.u_id');
  $builder-&gt;join('establishment as e', 'l.e_id = e.e_id');
  $data = $builder-&gt;get()-&gt;getResult();
  </code></pre>
  <p>Another thing that confused me is I don't know where should I put it. I don't know if I should put it on the <code>Controller</code> or on the <code>Model</code> file.</p>
  <p>So far, here's the code on my Controller.</p>
  <pre><code>public function getLogs(){
  helper(['form']);
  $model = new LogsMod();
  $rep_est = $this-&gt;request-&gt;getPost('rep_est');
  $rep_date = $this-&gt;request-&gt;getPost('rep_date');
  $data['logs_data'] = $model-&gt;where('DATE(l.date_added)', $rep_date)-&gt;groupBy(date_format(l.date_added, '%H:%i'), l.u_id)-&gt;orderBy('l.date_added', 'ASC')-&gt;findAll();
  return view()-&gt;to('LogsReport', $data);
  }
  </code></pre>
  <p>And here the code on my Model.</p>
  <pre><code>public function getLogs(){
  
  $builder = $this-&gt;db-&gt;table(&quot;logs as l&quot;);
  $builder-&gt;select('l.l_id, u.fname, u.mname, u.lname, u.dept, u.user_type, u.u_grdsec, e.e_name, l.date_added, DATE(l.date_added), date_format(l.date_added, &quot;%H:%i&quot;) as &quot;time&quot;');
  $builder-&gt;join('users as u', 'l.u_id = u.u_id');
  $builder-&gt;join('establishment as e', 'l.e_id = e.e_id');
  $data = $builder-&gt;get()-&gt;getResult();
  }
  </code></pre>
  <p>However, I don't think that the two are connected.</p>