Forum Moderators: open

Message Too Old, No Replies

Using distinct and sort ascending

         

bleak26

9:14 pm on May 11, 2006 (gmt 0)

10+ Year Member



I'm trying to write a query for a table which records visits to specific pages. I want to retrieve the last 10 visits that a specific user made ordered by date excluding visits to the same pages. My problem is that if I use distinct and order by date descending, the date field date stops my records from being distinct. This is because I may have multiple visits to the same page, by the same user, but at a different time.

How can I order by date, but not distinguished by date.

ChadSEO

9:37 pm on May 11, 2006 (gmt 0)

10+ Year Member



bleak26,

If you want both the page and most recent date, then something like this should work:

SELECT page,max(date) as maxdate
FROM mytable
GROUP BY page
ORDER BY maxdate desc
LIMIT 10;

Chad