Home All Groups Group Topic Archive Search About
Author
25 Mar 2006 10:21 AM
Niclas
Hi,

I am struggling with a SQL query and was hoping to get some help.

This is a simplifed scenario:

I have 2 tables

Table1 Results with 2 columns USERID (int) and RESULT (datetime)

Table 2 Users UserID (int), firstname (varchar), lastname(varchar)

The results table stores datetime values for each event a userID have a
result recorded.

I would like a query that produces a list containing each USERID that is
present in the results table with the best (lowest) result.

In effect this would produce a personal best list for each user. Any
suggestions on how this can be achieved would be much appreciated.

Regards

Nic

Author
25 Mar 2006 11:21 AM
Tom Moreau
I'm interpreting your spec as the earliest result per user:

select
    u.UserID
,   u.lastname
,   u.firstname
,   min (r.result) as result
from
    Table1 r
join
    Table2 u on u.UserID = r.UserID
group by
    u.UserID
,   u.lastname
,   u.firstname

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON   Canada
www.pinpub.com
..
"Niclas" <lindblom_nic***@hotmail.com> wrote in message
news:%23WCZVb$TGHA.4956@TK2MSFTNGP09.phx.gbl...
Hi,

I am struggling with a SQL query and was hoping to get some help.

This is a simplifed scenario:

I have 2 tables

Table1 Results with 2 columns USERID (int) and RESULT (datetime)

Table 2 Users UserID (int), firstname (varchar), lastname(varchar)

The results table stores datetime values for each event a userID have a
result recorded.

I would like a query that produces a list containing each USERID that is
present in the results table with the best (lowest) result.

In effect this would produce a personal best list for each user. Any
suggestions on how this can be achieved would be much appreciated.

Regards

Nic

AddThis Social Bookmark Button