Hey there!
I want to know how to do these 2 sql queries with CodeIgniter 4:
1. select max
Just a simple query like this:
Code:
select max(id) from table
My guess is this:
PHP Code:
$max = $this->myModel->selectMax('id')->get()->getFirstRow()->id;
However, it seems too difficult to understand. Two methods get + getFirstRow, two times "id" field name... Is there a better or easier to understand way?
2. Joins
I want to join the main table of a model with a secondary table. After getting the model I have a problem because the join creates two “id” fields. Manually writing the queries I can give an alias, such as 't1' and 't2' to the tables, so that I can say “orderby('t1.id'). But when getting the main table from the model, how can I set the alias or make it clear how to differentiate the main table from the secondary table?