Price database and confusing SQL query - 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: Price database and confusing SQL query (/showthread.php?tid=15864) Pages:
1
2
|
Price database and confusing SQL query - El Forum - 02-17-2009 [eluser]Relexx[/eluser] [quote author="MarcL" date="1234927082"]Sorry for my ignorance but I've been having a look at ActiveRecord and I'm not sure that I can do the inner query with it. Is that right?[/quote] you could always create a view for this instead Code: create view last_prices as select max(created_on) as created, product_id, merchant_id from prices Then join the view Code: select prc.id, prc.price, prd.id, prd.name, mer.name Price database and confusing SQL query - El Forum - 02-18-2009 [eluser]MarcL[/eluser] Thanks for the tips guys. [quote author="Relexx" date="1234955649"] Code: select prc.id, prc.price, prd.id, prd.name, mer.name Can I do this with ActiveRecord Relexx? Or, in fact, should I do this with ActiveRecord or is a straight db->query() the way to go for more complex queries? Price database and confusing SQL query - El Forum - 02-18-2009 [eluser]Relexx[/eluser] I would recommend that you use active record where ever possible. read ActiveRecord The below is not tested Code: $this->db->select ('prices.id, product.id, product.name, merchant.name'); You may be able to do this as well I am not sure. I would be interested to know if it does Code: $this->db->select ('prices.id'); Likewise the join clauses in the where could be replaced by using $this->db->join() but I am less familiar with this style of sql syntax. |