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
 General SQL Server Forums
 New to SQL Server Programming
 last login

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2007-05-09 : 23:33:27
Hello all!

I have a table called tbllogins where I am keeping the date/time and username of all users who log into the system. When they login I want to show them the last time the logged into the system. When I create the recordset for the last login, I simply sorting by username name, and then ordering by id (the pk) descending, or I realized I could sort by date desecending. The problem is that I would get the date and time of the current login and NOT the login before that. You see I'm inserting the login information immediately after a successful authentication. Thats means when I go to the newxt page and ask for the last login, I'm actually getting the login information for the login I just did. I want the login information for the login I did before that. How I can I query that?

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-05-09 : 23:48:33
For that u have to take the second large value from the table like..

Select Min(<login date>) from
(select top 2 <login date> from @tt where username = <login user> order by logindt desc) as a
Go to Top of Page
   

- Advertisement -