Unix Technical Forum

Distinct

This is a discussion on Distinct within the MySQL forums, part of the Database Server Software category; --> Hi i don't know how to get the last record of each distinct entries in one of my table ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:31 AM
Axelar
 
Posts: n/a
Default Distinct

Hi

i don't know how to get the last record of each distinct entries in
one of my table connexion. The table contains trace of connexions on a
website. The fields are id, date, hour, user, browser, pageviewed.

If i use "SELECT DISTINCT(user) FROM connexions ORDER BY date DESC,
heure DESC" i get just the name of the each user

If i use "SELECT DISTINCT(user),date,hour FROM connexions ORDER BY
date DESC, heure DESC" i get more than one line per user !?

What's the right way to obtain a list of each user last connexion ?

Thanks in advance !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:31 AM
J.O. Aho
 
Posts: n/a
Default Re: Distinct

Axelar wrote:
> Hi
>
> i don't know how to get the last record of each distinct entries in
> one of my table connexion. The table contains trace of connexions on a
> website. The fields are id, date, hour, user, browser, pageviewed.
>
> If i use "SELECT DISTINCT(user) FROM connexions ORDER BY date DESC,
> heure DESC" i get just the name of the each user
>
> If i use "SELECT DISTINCT(user),date,hour FROM connexions ORDER BY
> date DESC, heure DESC" i get more than one line per user !?
>
> What's the right way to obtain a list of each user last connexion ?
>
> Thanks in advance !


Try
SELECT user, date, hour FROM connexions ORDER BY date DESC , hour DESC GROUP
BY user

--

//Aho
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:31 AM
Axelar
 
Posts: n/a
Default Re: Distinct

On 22 déc, 12:14, "J.O. Aho" <u...@example.net> wrote:
> Axelar wrote:
> > Hi

>
> > i don't know how to get the last record of each distinct entries in
> > one of my table connexion. The table contains trace of connexions on a
> > website. The fields are id, date, hour, user, browser, pageviewed.

>
> > If i use "SELECT DISTINCT(user) FROM connexions ORDER BY date DESC,
> > heure DESC" i get just the name of the each user

>
> > If i use "SELECT DISTINCT(user),date,hour FROM connexions ORDER BY
> > date DESC, heure DESC" i get more than one line per user !?

>
> > What's the right way to obtain a list of each user last connexion ?

>
> > Thanks in advance !

>
> Try
> SELECT user, date, hour FROM connexions ORDER BY date DESC , hour DESC GROUP
> BY user
>
> --
>
> //Aho


Seems like i can't use GROUP BY after ORDER BY
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:31 AM
Paul Lautman
 
Posts: n/a
Default Re: Distinct

Axelar wrote:
> Hi
>
> i don't know how to get the last record of each distinct entries in
> one of my table connexion. The table contains trace of connexions on a
> website. The fields are id, date, hour, user, browser, pageviewed.
>
> If i use "SELECT DISTINCT(user) FROM connexions ORDER BY date DESC,
> heure DESC" i get just the name of the each user
>
> If i use "SELECT DISTINCT(user),date,hour FROM connexions ORDER BY
> date DESC, heure DESC" i get more than one line per user !?
>
> What's the right way to obtain a list of each user last connexion ?
>
> Thanks in advance !


Yawn, once again the answer is the "strawberry query". If I had a penny for
every time I have answered this question!

http://dev.mysql.com/doc/refman/5.0/...group-row.html

the query you are looking for is the one with the LEFT JOIN.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com