Distinct

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


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-22-2007
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 !
Reply With Quote
  #2 (permalink)  
Old 12-22-2007
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
Reply With Quote
  #3 (permalink)  
Old 12-22-2007
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
Reply With Quote
  #4 (permalink)  
Old 12-22-2007
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.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:47 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0