[SOLVED] How to use MySQL alias join with CI's 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] How to use MySQL alias join with CI's Active Record (/showthread.php?tid=43340) |
[SOLVED] How to use MySQL alias join with CI's Active Record - El Forum - 07-08-2011 [eluser]tkaw220[/eluser] Hi, I have recently working with CI's Active Record class. Consider I have below code, where the code retrieve data from two table by using join. How can I improve below code by using MySQL alias? i.e., Code: select inventory_logs as l Code: $this->db->select('inventory_logs.log_no, inventory_logs.transaction, inventory_logs.type, inventory_logs.purchase_order, inventory_logs.job_sheet, inventory_logs.invoice, inventory_logs.delivery_order, inventory_logs.note, inventory_logs.user, inventory_logs.log_date, booksellers.name') Many thanks. 7/14/2011: Found this solution from Grey Aker's blog. Thanks Grey. Code: $qry = $this-db->select('m.member_id, m.group_id, m.username, m.screen_name, m.email, m.url, m.location, g.group_title') Hope someone find this helpful. [SOLVED] How to use MySQL alias join with CI's Active Record - El Forum - 07-08-2011 [eluser]danmontgomery[/eluser] Code: $this->db->select('inventory_logs.log_no as l, ... [SOLVED] How to use MySQL alias join with CI's Active Record - El Forum - 07-08-2011 [eluser]tkaw220[/eluser] Hi noctrum, Is my code below correct? Code: $this->db->select('inventory_logs.log_no as l, l.transaction, l.bookseller_id, l.type, l.purchase_order, l.job_sheet, l.invoice, l.delivery_order, l.note, l.user, l.log_date, booksellers.name as b, b.id') Thank you. [SOLVED] How to use MySQL alias join with CI's Active Record - El Forum - 07-08-2011 [eluser]jmadsen[/eluser] no, you need to alias your table, not your field, for what you are doing. Take it out of Active Record for a moment and look at what you are writing [SOLVED] How to use MySQL alias join with CI's Active Record - El Forum - 07-08-2011 [eluser]danmontgomery[/eluser] To alias the table instead of the column: Code: $this->db->get('inventory_logs as l', 1); |