Help building a query using ActiveRecord - 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: Help building a query using ActiveRecord (/showthread.php?tid=35120) Pages:
1
2
|
Help building a query using ActiveRecord - El Forum - 10-19-2010 [eluser]stormbytes[/eluser] What are the steps to follow to build the following query using ActiveRecord? (Read the manual...) Code: SELECT I'm having trouble figuring out how to piece this together using db->select() & db->join() or is it that ActiveRecord is more suited for simple queries? Should I be doing this using db->query? Help building a query using ActiveRecord - El Forum - 10-19-2010 [eluser]cahva[/eluser] This can be done with AR no problemo: Code: $q = $this->db->select("CONCAT(u.user_first_name,' ',u.user_last_name) User,a.account_numb Account,s.state State",FALSE) I left out AS (the alias). It is not used by some DBMS(at the time) so I left it out couple of years ago. Help building a query using ActiveRecord - El Forum - 10-20-2010 [eluser]stormbytes[/eluser] Hiya, cahva! Well.. It took a couple of hours futzing around to adapt that to my code, but it worked like a charm! Thanks so much for posting the tip. Help building a query using ActiveRecord - El Forum - 10-24-2010 [eluser]pbreit[/eluser] Would "where" work ok instead of the two joins? Pros & cons? Help building a query using ActiveRecord - El Forum - 10-24-2010 [eluser]stormbytes[/eluser] How's a 'where' replace the joins? Help building a query using ActiveRecord - El Forum - 10-25-2010 [eluser]pbreit[/eluser] Isn't this the same query? Code: SELECT Help building a query using ActiveRecord - El Forum - 10-25-2010 [eluser]techgnome[/eluser] But for the fact that you didn't specify the join condition for the State table... in theory, yes... but not all DBMSs support that method of joining. And doesn't allow for left, right or outer joins, it's only effective with inner joins. -tg Help building a query using ActiveRecord - El Forum - 10-25-2010 [eluser]pbreit[/eluser] Isn't this the join condition for states? Code: AND u.state_id = States.state_id Help building a query using ActiveRecord - El Forum - 10-25-2010 [eluser]tonanbarbarian[/eluser] most databases, mysql in particular are optimised to work better with joins rather than just using multiple from and where statements joins is also the standard sql way of doing things so you should use them wherever possible. you have more control over how the join works etc if you use a join rather than the from where Help building a query using ActiveRecord - El Forum - 10-25-2010 [eluser]marrysmile23[/eluser] ActiveRecord provides an excellent way to manage your database entities. When it comes to the pursuit and acquisition of these entities in a flexible, ActiveRecord can do the trick in many cases, using different criteria. |