I have a query like this (Mysql 5.X, PHP - formatted for legibility)
$query ="
SELECT
p.p_pid,
p.p_name,
p.p_url
FROM
activity a,
products p
WHERE
a.a_uid= ".$uid_int."
AND a.a_pid > 0
AND p.p_pid = a.a_pid
GROUP BY
a.a_pid
ORDER BY
a.a_time DESC LIMIT 6
");
In general it should produce a unique list of the 6 latest products the user has seen.
The problem is that if the user has seen a product more than once. one of them in the last 6 activities and one of them before the latest 6 activities the query does not return the product. I assume that the (group by) does not leave a_time with the latest time of apperance of the product. How can I correct it?