Price database and confusing SQL query |
[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
[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?
[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. |
Welcome Guest, Not a member yet? Register Sign In |