selecting from multiple tables - 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: selecting from multiple tables (/showthread.php?tid=18983) |
selecting from multiple tables - El Forum - 05-24-2009 [eluser]blu3ness[/eluser] I'm trying to do an old fashion select from two tables in plain SQL it'll prob be something like this Code: SELECT a.title, a.desc,b.title as cat_title,b.desc as cat_desc How would you accomplish this using activerecord? I tried Code: $this->db->select('*')->from('products')->where('category_id',$category_id)->join('categories','products.category_id=categories.id'); which only gets me the first table data and nothing from the second. Tyvm selecting from multiple tables - El Forum - 05-24-2009 [eluser]TheFuzzy0ne[/eluser] I wonder if this will work any better: Code: $this->db->select('a.title, a.desc, b.title AS cat_title, b.desc AS cat_desc'); I'm not entirely sure about this but you might need to move the call to $this->db->select() to under the from and join calls. I seem to recall that CodeIgniter had a problem with tracking alias', but I am not certain that I recall correctly. selecting from multiple tables - El Forum - 05-24-2009 [eluser]blu3ness[/eluser] Code: $this->db->select('a.*, b.title AS cat_title') Thanks TheFuzzyOne |