CodeIgniter Forums

Full Version: Double select in builder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For a database query im joining 2 tables. I want to add a second select since both tables have an id column. What i want:

Codeigniter 2:
PHP Code:
$this->db->select(" AS id");
$this->db->join("second_table"," = second_table.base_id","INNER");
$query $this->db->get("main_table"); 

Codeigniter 4:
PHP Code:
$db = \Config\Database::connect();
$builder $db->table('main_table');
$builder->select(" AS id");
$builder->join("second_table"," = second_table.base_id","INNER");
$query $builder->get(); 

But in Codeigniter 4 this doesnt seem to work $query->getResult() returns just the id column.

Any ideas?
try $builder->select("second_table.*, AS id");
thanks, ive managed to fix it as follows:
$db = \Config\Database::connect();
$builder = $db->table('main_table');

$builder->selects[] = "*";
$builder->selects[] = " as id";

$builder->join("second_table"," = second_table.base_id","INNER");
$query = $builder->get();

Seems the select needed to have an array.