[solved] Inner Join Active Record - 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: [solved] Inner Join Active Record (/showthread.php?tid=14208) |
[solved] Inner Join Active Record - El Forum - 12-22-2008 [eluser]a&w[/eluser] I was trying to leverage Active Record to do a join. Below I'm showing one that works and one that doesn't. This version works. Active record query generation: Code: $this->db->from('table_1'); generates this query: Code: SELECT * And I get results. Ok good. But I had to manually do the "WHERE" clause. So I tried to do generate the same query using a join: Code: $this->db->from('table_1'); But that generates this query: Code: SELECT * Which has this result: Code: Error Code : 1066 [solved] Inner Join Active Record - El Forum - 12-22-2008 [eluser]Armchair Samurai[/eluser] It seems like you're not using the join() function correctly. Try this (hasn't been tested, but should give you what you need): Code: $this->db->join('table_2', 'table_1.id = table_2.id', 'inner'); [solved] Inner Join Active Record - El Forum - 12-22-2008 [eluser]a&w[/eluser] Thanks for your help, yields same result: Previous query: Code: FROM (`table_1`, `table_2`) With your code (same thing pretty much...same result nonetheless): Code: <h1>A Database Error Occurred</h1> [solved] Inner Join Active Record - El Forum - 12-22-2008 [eluser]a&w[/eluser] How approaching this a different way? Forget CI. IF you had to build the sql query using a join statement what would the sql query look like? Because I was also just testing the query against mysql and getting the same result. So this is more of an issue with the query itself (at least at this point). [solved] Inner Join Active Record - El Forum - 12-22-2008 [eluser]a&w[/eluser] Ok, got it resolved, was fairly close actually, but close just doesn't get it done in this case. The query should have been: Code: SELECT * And to get that: Code: $this->db->select('*'); |