0

Trying to calculate the time difference between current time and the user's settime to get results in minutes and it works, but is there a way to save the same result into table column on the latest row?

SELECT settime, TIMESTAMPDIFF(MINUTE,CURRENT_TIMESTAMP(), settime)AS timeleft 
FROM feedtime

enter image description here On the left side image, it shows result "timeleft" correctly but also an error Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. Where as my id column is already set as primary, unique and auto_increment

Is there a way i could take the result and update into right side image shown column as timeleft?

1 Answer 1

1

Yes, use an UPDATE statement:

UPDATE feedtime
SET timeleft = TIMESTAMPDIFF(MINUTE, CURRENT_TIMESTAMP(), settime);

Note that MySQL may insist that you add a WHERE clause which uses a condition on the id column, e.g.

UPDATE feedtime
SET timeleft = TIMESTAMPDIFF(MINUTE, CURRENT_TIMESTAMP(), settime)
WHERE id = 1;

Even if MySQL does not require this, you still might want to add a WHERE clause to limit the scope of the update.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked, i was trying INSERT INTO feedtime instead of UPDATE as you said

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.