The goal of this query is to get a total of unique records (most recent per IP, by IP) per ref ID.
SELECT COUNT(DISTINCT ip), GROUP_CONCAT(ref.id)
FROM `sess` sess
JOIN `ref` USING(row_id)
WHERE sess.time BETWEEN '2010-04-21 00:00:00' AND '2010-04-21 23:59:59'
GROUP BY ref.id
ORDER BY sess.time DESC
The query works fine, but its using a temporary table. Any ideas?
The row_id is the primary on both tables. sess.time, sess.ip, and ref.id are all indexes.