RE: [PHP] SQL DISTINCT with MYSQL
| From: | Uttam | Date: | Fri, 14 Mar 2003 10:17:47 +0000 |
| Subject: | RE: [PHP] SQL DISTINCT with MYSQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-139694@lists.php.net to get a copy of this message | ||
here's my solution:
I presume you need the name of the file the user last accessed.
This requires a datetime column in your useronline file which records the
time a user has accessed a page. If the name of this field is atime then
a) create a temporary table storing lact access time for each user
CREATE TEMPORARY TABLE tmp SELECT uname, MAX(atime) FROM useronline
GROUP BY uname;
b) select the uname, file by joining the useronline table with this
temporary table:
SELECT useronline.uname, useronline.file
FROM useronline INNER JOIN tmp
ON useronline.uname=tmp.uname AND useronline.atime=tmp.atime
You can index on atime field for faster results.
hope it helps...
regards,
-----Original Message-----
From: Vernon [mailto:vernon@comp-wiz.com]
Sent: Friday, March 14, 2003 06:20
To: php-general@lists.php.net
Subject: Re: [PHP] SQL DISTINCT with MYSQL
The problem is
> a f1
> a f2
> b f1
> b f2
Where I need it to return the a only once and the b only once. For
instance
the vlaues may be:
jimmy login.php
jimmy successfullogin.php
susan default.php
susan search.php
Since the records are order the way I need them to be (or else I could
use a
ORDER BY command) the last one is the only one I want and only want to
return:
jimmy successfullogin.php
susan search.php
make sense?
"Arturo Barajas" <abarajas@ppg.com> wrote in message
news:396E8F0264F4D611A28800105A285FA3221625@ssjdusr01.crmx.ppg.com...
> Vernon,
>
> Don't know if I get it right, but:
>
> SELECT DISTINCT uname, file
> FROM useronline
>
> should do that.
>
> I mean, if you have something like:
>
> uname file
> a f1
> a f2
> a f1
> a f2
> b f1
> b f2
> b f1
>
> the query should deliver:
>
> uname file
> a f1
> a f2
> b f1
> b f2
>
> Is that what you're looking for?
> --
> Un gran saludo/Big regards...
> Arturo Barajas, IT/Systems PPG MX (SJDR)
> (427) 271-9918, x448
>
> > -----Original Message-----
> > From: Vernon [mailto:vernon@comp-wiz.com]
> > Sent: Jueves, 13 de Marzo de 2003 06:24 p.m.
> > To: php-general@lists.php.net
> > Subject: [PHP] SQL DISTINCT with MYSQL
> >
> >
> > I'm setting up a user online system using MySQL where I have
> > 4 fields, all
> > of which is working fine.
> >
> > I need the information from all the fields but want only
> > distinct values
> > based on the uname column. If I use the:
> >
> > SELECT DISTINCT uname
> > FROM useronline
> >
> > of course I come back with the values I desire, but only the
> > user names.
> >
> > As I am also tracking the page they are on I need other
> > columns in the table
> > as well. So the question is, using an SQL statement, how do I
> > return only
> > distinct useronline.uname values from the database as well as the
> > useronline.file column?
> >
> > Thanks
> >
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php