SQL Recipes
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 06-04-2007, 03:53 PM
Lossandra Lossandra is offline
Junior Member
 
Join Date: Jun 2007
Posts: 2
Lossandra is on a distinguished road
Default ANY dialect question:

How to find distinct users based on last logon


assume a table as follows:

User(Id) LastOn(Date) Duration(long)
U1 May 4 10 minutes
U1 May 5 5 minutes
U2 May 1 12 minutes
U2 May 3 27 minutes

I'm looking for a query that'd give me

U1 May 1 5 minutes
U2 May 3 27 minutes
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 06-04-2007, 10:11 PM
Dimitar
 
Posts: n/a
Default ANY answer. Re: How to find distinct users based on last logon

SELECT * FROM users t0 WHERE laston=(SELECT max(t1.laston) FROM users t1 WHERE t0.id=t1.id);

Discussion: if the user has logged on multiple times the same last logon day, then there would be multiple rows in the result for that user and you need more criteria to differentiate between those rows.

Hoe this helps,

Dimitar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-05-2007, 09:13 AM
Lossandra Lossandra is offline
Junior Member
 
Join Date: Jun 2007
Posts: 2
Lossandra is on a distinguished road
Default ANY answer. Re: How to find distinct users based on last logon

Thank you very much for the quick answer. That solved the problem for me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-27-2008, 10:11 PM
orshoe@gmail.com
 
Posts: n/a
Default ANY answer. Re: How to find distinct users based on last logon

Hi, on similar lines, if I have a table with accounts, users and last_on_date, how can I find the user who accessed an account most recently.

Say, the table is as follows:
a/c user date
---- ---- -----------
a1 u1 03/04/2007
a1 u2 03/05/2007
a2 u3 03/05/2007
a2 u1 03/07/2007
a2 u2 03/06/2007
a3 u3 04/05/2007

What query would fetch the following:
a/c user date
---- ---- -----------
a1 u2 03/05/2007
a2 u1 03/07/2007
a3 u3 04/05/2007

Any help is appreciated.
Orshoe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-03-2008, 06:31 PM
chintaguntareddy chintaguntareddy is offline
Junior Member
 
Join Date: Mar 2008
Posts: 1
chintaguntareddy is on a distinguished road
Default ANY answer. Re: How to find distinct users based on last logon

i guess it sama as above code.....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



All times are GMT. The time now is 03:47 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2008 SQL Recipes

1 2 3 4 5 6 7 8