Welcome Guest, Not a member yet? Register   Sign In
Can anyone help me with this one.
#1
Information 

http://sqlfiddle.com/#!9/a9ec7e/4/0

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.
Reply
#2

Fast Option:

PHP Code:
$query $this->db->query('YOUR QUERY HERE'); 

Or maybe create a view (without order) and use like a table.
Reply
#3

(10-22-2020, 05:52 AM)ElTomTom Wrote: Fast Option:

PHP Code:
$query $this->db->query('YOUR QUERY HERE'); 

Or maybe create a view (without order) and use like a table.
Hi. Thanks for your answer. Yup. I solved it already using a variable $query and then return $query->result();

Thank you.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB