abu abu
abu abu

Reputation: 7028

Fetch data from same named two columns of two tables

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

Upvotes: 0

Views: 302

Answers (1)

raphalg
raphalg

Reputation: 468

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');

Upvotes: 3

Related Questions