http://sqlfiddle.com/#!9/a9ec7e/4/0
Thats exactly what i need for my project.
But i can't / dont know how to do this query in codeigniter.
Im using CodeIgniter 3.
Code:
SELECT
p.*
FROM
(
-- For every product_id, find maximum created_at time
SELECT
product_id, max(created_at) AS created_at
FROM
purchases
GROUP BY
product_id
) AS mx
-- JOIN to the whole table
JOIN purchases p ON
mx.product_id = p.product_id AND mx.created_at = p.created_at
ORDER BY
product_id ;
Thats exactly what i need for my project.
But i can't / dont know how to do this query in codeigniter.
Im using CodeIgniter 3.