Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
drumm
Starting Member
14 Posts |
Posted - 2003-01-20 : 07:48:13
|
| Hello,I have a table into which I log whenever a user logs into my portal. I need an SQL statement that can help find the most recent login for every user returned as a single resultset.Thanks in advance,Thomas |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2003-01-20 : 07:57:27
|
| If you supplied DDL for your tables you would get a better answer. You need something likeSELECT distinct user_name, max (login_time) from yourtablegroup by user_name-------Moo. |
 |
|
|
Crespo24
Village Idiot
144 Posts |
Posted - 2003-01-20 : 08:02:28
|
quote: If you supplied DDL for your tables you would get a better answer. You need something likeSELECT distinct user_name, max (login_time) from yourtablegroup by user_name-------Moo.
LOL mist.... what the hell are you using DISTINCT for if you have a group by on user_name! Thanks mist, now I know that I am not the only n00b SQLer around here  |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2003-01-20 : 08:19:47
|
| Hmm. For some reason I was thinking it produces a row for each occurance of user_name.Still there's no difference, it runs to exactly the same plan.My excuse is that the word distinct makes it more obvious...-------Moo. |
 |
|
|
drumm
Starting Member
14 Posts |
Posted - 2003-01-20 : 08:46:29
|
| Hi guys,thanks for your help, it was so simple that I didn't see it.Recently we had the same problem, except that we needed the top 3 timestamps per user (which is a bit more difficult to extract), and this is why I was working on some far out SQL statements.Thanks! |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2003-01-20 : 09:26:45
|
quote: Recently we had the same problem, except that we needed the top 3 timestamps per user (which is a bit more difficult to extract), and this is why I was working on some far out SQL statements.
Here is some stuff about "top N of a group".Jay White{0} |
 |
|
|
|
|
|
|
|