in codeigniter how do i do a join with a where clause in codeigniter how do i do a join with a where clause codeigniter codeigniter

in codeigniter how do i do a join with a where clause


It's been a while since I wrote CI, but as per this docs page, your solution might look like this:

$this->db->select('*');$this->db->from('table1');$this->db->join('table2', 'table1.col1 = table2.col1');$this->db->where('table1.col1', 2);$query = $this->db->get();

note this answer is in no way to be construed as an endorsement of working with Code Igniter ;-)


Try this :

$this->db->select('*'); // Select field$this->db->from('table1'); // from Table1$this->db->join('table2','table1.col1 = table2.col1','INNER'); // Join table1 with table2 based on the foreign key$this->db->where('table1.col1',2); // Set Filter$res = $this->db->get();

Hope it helps :)


$this->db->select('book_id, book_name, author_name, category_name');$this->db->from('books');$this->db->join('category', 'category.category_id = books.category_id');$this->db->where('category_name', 'Self Development');$query = $this->db->get();// Produces SQL: select book_id, book_name, author_name, category_name from books  join category on category.category_id = books.category_id  where category_name = "Self Development"