0

So my question is:

Is it possible to select all data from different tables in one query?

Example1:

$query = $this->db->get('table1');
$query = $this->db->get('table2');
$query = $this->db->get('table3');

return $query->result();

Example2:

$this->db->select('*');
$this->db->from('table1', 'table2', 'table3');

$query = $this->db->get();

return $query->result();

I think the second exaple is possible. If not i want to ask how you would do that.

Thank you.

1 Answer 1

1

It can be done by putting the table names in an arrary

$query = $this->db
    ->select('*')
    ->from(['table1', 'table2'])
    ->get();
return $query->result();

But the number of rows in the result will be the product of the number of rows in each table, i.e. table1 has 3 rows and table2 has 19 you'll get 57 rows in the result. Are you sure that's what you want?

Joins are easy to write and highly efficient. Don't be afraid of them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.