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 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-08-11 : 08:03:19
|
| Hello Everyone.I want to get the last 10 user who have logged in to the system. The user name should be unique. if one user have logged in twice then it should not come.The Sample data.UserCode LoginDatetime UserDesc10606 2005-08-08 12:29:54.787 User1HO0189 2005-08-08 12:29:14.900 NULL10149 2005-08-07 16:16:46.353 User210606 2005-08-07 16:16:10.280 User110606 2005-08-07 16:16:06.763 User110606 2005-08-07 16:16:03.717 User1GOD 2005-08-07 14:28:23.700 NULLGOD 2005-08-06 14:37:08.623 NULL10606 2005-08-01 15:54:43.127 User110606 2005-08-01 15:54:34.173 User1this i have pullout using order by login time desc.. but i want the unique user name... Thanks.. Complicated things can be done by simple thinking |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-11 : 08:04:20
|
| Select Top 10 * from yourTable order by LoginTime DescMadhivananFailing to plan is Planning to fail |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-08-11 : 08:13:44
|
| yea.. that what i did.. but i want the last distinct user id .. who have logged in the system ..i hope u got it.Complicated things can be done by simple thinking |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-08-11 : 08:15:23
|
| SELECT TOP 10 UserDesc, Max(LoginDateTime) LastLogin FROM myTable GROUP BY UserDesc ORDER BY LastLogin DESC |
 |
|
|
kapilarya
Yak Posting Veteran
86 Posts |
Posted - 2005-08-11 : 08:20:30
|
| SELECT TOP <N> UserDesc, Max(LoginDateTime) LastLogin FROM <YourTable> GROUP BY UserDesc ORDER BY 2DESCKapil Arya |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-08-11 : 08:24:40
|
| Thanks a lot both of urs Kapil.. and robvolk worked for me.. :-)... .Complicated things can be done by simple thinking |
 |
|
|
|
|
|