By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

updating most recent entry, regardless of previous records in database

100+
P: 126
I have a login table which as columns name, employee_id, date,login, logout; everything works fine until a regular updation of login and logout is done(i.e every login having a logout). my problem is when the person forgets to logout, and next session or next day he login's and again logout's the previous un-updated cell also gets updated which should not happen.

Result obtained now:
When the person forgets to logout and login's again
Expand|Select|Wrap|Line Numbers
  1.     name      emp_id  date       login        logout
  2.     Preethi    002   1/11/13    09::0:00     00:00:00
  3.     preethi    002   1/11/13    12:24:13     00:00:00 
  4.  
later logout result
Expand|Select|Wrap|Line Numbers
  1.     name      emp_id  date       login        logout  
  2.     Preethi    002   1/11/13    09::0:00     10:15:54  
  3.     preethi    002   1/11/13    12:24:13     10:15:54  
  4.  


Expected result:
Expand|Select|Wrap|Line Numbers
  1.     name      emp_id  date       login        logout
  2.     Preethi    002   1/11/13    09::0:00     00:00:00
  3.     preethi    002   1/11/13    12:24:13     10:15:54
  4.  
Jan 11 '13 #1
Share this Question
Share on Google+
1 Reply


100+
P: 126
I solved my problem,
here is the code -
Expand|Select|Wrap|Line Numbers
  1. update table_name set logout = now() order by sl desc limit 1
sl(serial number) is a column for ordering
Jan 11 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.