Home > Software design >  Fetch data from same named two coloumn of Two table
Fetch data from same named two coloumn of Two table

Time:01-12

I am trying to fetch data from 2 tables with Join Query. Here I have 2 columns in 2 tables with same column name. My query is like below.

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