I have a table with site visits with the following columns:
timestamp
host
url
I would like to see the last few (say 200) visits but at the same time group visits of the same host together (to see the sequence of pages he/she visits).
If I do:
... SORT BY timestamp DESC, host
I get hosts mixed up if several visitors are online at the same time
If I do:
... SORT BY host, timestamp DESC
I do not get the latest visits (just the latest visits from each host)
I would like to see e.g.
9:01 | a.com | /index
9:05 | a.com | /interesting
9:07 | a.com | /contact
9:02 | b.com | /index
9:03 | b.com | /product-a
9:08 | b.com | /thanks-for-buying
Is that possible in Mysql or should I further process the result in php?
The answers above pointed my in the right direction, thanks. This one works. The LIMIT 1000 is to reduce the query from almost 3 minutes to 7 seconds (40000 records).