PDA

View Full Version : MYSQL query


Neo
03-06-2002, 10:58 PM
I am stuck on a way of extracting unique entries from a dbase.

basically what i have is a table that holds 'users' that accessed certain 'pages' on certain 'dates'.

i want to sort by users then show last page accessed, however i have 2000+ users that access 300 different pages so i need a way to sort and extract unique entries.

e.g. sort into 'users'/'dateaccesed' and only pull the last 'page' that each user accessed into a while loop.

is there a way of calling this into a single query, then run a while loop on the result?

please help i am going nuts and the routine i have at the mo takes 43 secs for each run.

top5mov
03-07-2002, 09:24 AM
can you post your database structure, i.e., the names of the tables and their respective fields?

Neo
03-07-2002, 09:46 AM
hi,
my db structure is as follows

tablename:
'tracking'

fields:
'tid' [int(10)] autoincrement
'tusername' [varchar(25)]
'tip' [varchar(16)]
'tdate' [int(10)]
'tpage' [varchar(200)]

population example

1,johnp,192.168.0.23,1015506411,index.php
2,mikej,192.168.0.24,1015506413,index.php
3,mikej,192.168.0.24,1015506427,forum.php
4,mikej,192.168.0.24,1015506444,mail.php
5,johnp,192.168.0.23,1015506445,mail.php
2,carols,192.168.0.20,1015506450,index.php
6,mikej,192.168.0.24,1015506456,mail.php
7,johnp,192.168.0.23,1015506459,forum.php
8,carols,192.168.0.20,1015506467,mail.php

top5mov
03-07-2002, 10:36 AM
SELECT tusername, MAX(tdate) AS tdate, tip, tpage FROM tracking GROUP BY tusername

Neo
03-07-2002, 01:38 PM
That is so kewl...

thank you so much top5mov it is very much appreciated.