Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:54:01+00:00 2026-06-07T16:54:01+00:00

I have a table student_log , and there are multiple records for a single

  • 0

I have a table student_log, and there are multiple records for a single 'rollno'.

'sno' is the auto_increment index of the student_log table.

Suppose I want to update the value of a particular field for the last(most-recent) entry of a particular student(looked up by ‘rollno’), how do I do it? My current approach does not work. I am doing this:

update student_log set timein=current_timestamp() where rollno='ST001' and 
sno = (select sno from student_log where rollno='ST001' order by sno desc limit 1);

Using the subquery, I am trying to retrieve the sno of the most recent record where the student’s rollno matches. And I am trying to use it to match sno with the update statement, which isn’t working.

I know the syntax is correct, but I think it just means that MySQL does not allow update to use subqueries. Thanks. Ask me if I have missed out any information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:54:03+00:00Added an answer on June 7, 2026 at 4:54 pm
    UPDATE student_log
    SET timein=current_timestamp()
    WHERE rollno='ST001'
    ORDER BY sno DESC
    LIMIT 1
    

    EDIT
    tested my query, and yes its posible, or what did i miss in OPs table structure

    mysql> UPDATE student_log
        -> SET timein=current_timestamp()
        -> WHERE rollno='ST001'
        -> ORDER BY sno DESC
        -> LIMIT 1;
    Query OK, 1 row affected, 1 warning (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> SELECT * FROM student_log;
    +-----+--------+---------------------+
    | sno | rollno | timein              |
    +-----+--------+---------------------+
    |   1 | st001  | 0000-00-00 00:00:00 |
    |   2 | st002  | 0000-00-00 00:00:00 |
    |   3 | st001  | 2012-07-11 12:05:23 |
    +-----+--------+---------------------+
    3 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a student table, having around 5,000 records, in my DB. I want
I have a table of student scores. Students can take the test multiple times,
I have a database table named 'student' in which there is one column named
I have a table student(id, name, department, age, score). I want to find the
I am using SQL Server 2008. I have a Student table in which there
i have a table named students which have student details id,mark,name i want to
i have table student,fields are student_id, student_name, year_joining ... now i want to rename
I have a table with Student ID, Service, and Provider. I want to show
Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
I have 507 tables with (pattern = human). Inside each table there are a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.