problem with database query - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: problem with database query (/showthread.php?tid=43429) |
problem with database query - El Forum - 07-11-2011 [eluser]dagon[/eluser] Hello Im quite new to code igniter and the concept of active record pattern of database handling. I have problems with translating such SQL query into a series of active record method calls: select TA.*, count(*) as num_entries from table_a AS TA inner join table_b AS TB ON TB.id_category = TA.id GROUP BY TB.id_category ORDER BY num_entries DESC; Can anyone help ? I have aspecially problems with adapting count(*). problem with database query - El Forum - 07-11-2011 [eluser]danmontgomery[/eluser] Code: $query = $this->db problem with database query - El Forum - 07-11-2011 [eluser]dagon[/eluser] Thank You vey much. It works !!! problem with database query - El Forum - 07-12-2011 [eluser]dagon[/eluser] It seems that I ran onto another obstacle. Im trying to delete data from two tables using join(). but $this->db->delete() seems to take into consideration only previous declarations of where(), any joins are ommited. The query which I want to perform is: DELETE TA,TB FROM table_a AS TA LEFT JOIN table_b AS TB ON TA.id = TB.other_id WHERE TA.field = 'value'; I try to solve it like this: $this->db->from('table_a AS TA'); $this->db->where('TA.field', $value); $this->db->join('table_b AS TB', 'TA.id = TB.other_id', 'left'); $this->db->delete(); It seems that the above code does not generate the "JOIN" part of the query. Anyone know why ? Maybe this is a bug ? |