Jinu Joseph Daniel
Jinu Joseph Daniel

Reputation: 6291

Codeigniter active record how to join five tables

I have the following database schemaenter image description here

I am using codeigniter.I need to get data from all the tables ,by giving id of question_banks table.So how should I write the join clause for this using active record class of codeigniter.I know it is possible to join two tables.But how can I join all these tables.

Upvotes: 1

Views: 215

Answers (1)

lyhong
lyhong

Reputation: 947

It is not the best one but I think it will help

$this->db->select('questions.question, question_categories.name, options.value, question_banks.name');    
$this->db->from('questions');
$this->db->join('question_categories', 'questions.question_category_id = question_categories.id');
$this->db->join('options','options.option_id=questions.id');
$this->db->join('question_bank_questions', 'questions.id = question_bank_questions.question_id');
$this->db->join('question_banks', 'question_bank_questions.question_bank_id = question_bank.id');

Upvotes: 3

Related Questions