Home > Net >  Fetch data from same named two columns of two tables
Fetch data from same named two columns of two tables

Time:01-13

I am trying to fetch data from 2 tables with a join query. Here I have 2 columns in 2 tables with same column name.

This is my query:

public function get_all_expenses()
{
        $this->db->select("*",'category.name as cat_name');
        $this->db->from('expense');
        $this->db->join('category','expense.cat_id = category.id');
        $this->db->join('users','expense.user_id = users.id');
        $query = $this->db->get();

        return $query;
}

I can fetch data of 1 column of 1 table. But I can't fetch data of another column of another table. I am using CodeIgniter.

enter image description here

CodePudding user response:

According to the CodeIgniter documentation the database select method accept a single argument. The correct syntax for the select is then:

$this->db->select('*, category.name as cat_name');
  •  Tags:  
  • Related