![]() |
ActiveRecord Self Join output does not match SQL output - 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: ActiveRecord Self Join output does not match SQL output (/showthread.php?tid=53947) |
ActiveRecord Self Join output does not match SQL output - El Forum - 08-15-2012 [eluser]jelatin[/eluser] I have a piece of SQL, it's returning the exact data I want. Code: SELECT t1.id, t1.material, t2.id, t2.material, t3.id, t3.material, t4.id, t4.material It returns: Code: id | material | id | material | id | material | id | material Perfect, okay, now to put it in ActiveRecord: Code: $this->db->select('t1.id, t1.material, t2.id, t2.material, t3.id, t3.material, t4.id, t4.material'); Looks good, but it outputs: Code: ( Hmm, where are the first 6 things from my select() statement? $this->db->last_query() returns: Code: SELECT `t1`.`id`, `t1`.`material`, `t2`.`id`, `t2`.`material`, `t3`.`id`, `t3`.`material`, `t4`.`id`, `t4`.`material` Which I paste into SQL and it gives me the exact results I want. ActiveRecord Self Join output does not match SQL output - El Forum - 08-15-2012 [eluser]Massaki[/eluser] instead of: Code: return $this->db->get()->row(); Code: return $this->db->get()->result_array(); ActiveRecord Self Join output does not match SQL output - El Forum - 08-15-2012 [eluser]jelatin[/eluser] Turns out Code: $this->db->select('t1.id, t1.material, t2.id, t2.material, t3.id, t3.material, t4.id, t4.material'); Needed to be Code: $this->db->select('t1.id AS t1id, t1.material AS t1material, t2.id AS t2id, t2.material AS t2material, t3.id AS t3id, t3.material AS t3material, t4.id AS t4id, t4.material AS t4material'); |