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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Last 10 Records..

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 UserDesc
10606 2005-08-08 12:29:54.787 User1
HO0189 2005-08-08 12:29:14.900 NULL
10149 2005-08-07 16:16:46.353 User2
10606 2005-08-07 16:16:10.280 User1
10606 2005-08-07 16:16:06.763 User1
10606 2005-08-07 16:16:03.717 User1
GOD 2005-08-07 14:28:23.700 NULL
GOD 2005-08-06 14:37:08.623 NULL
10606 2005-08-01 15:54:43.127 User1
10606 2005-08-01 15:54:34.173 User1

this 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 Desc

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page

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 2DESC

Kapil Arya
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -