Paul Ømega February 2016

MySQL: Attendance Monitoring App Trouble

How do I update a specific field without replacing all the other fields with the same row field.

For example: I want to change this.(figure 1)

    date_id    employee_id    time_in     time_out
      1            3           1:00P        2:00P
      2            2           3:20P        3:49P
      3            2           3:20P        3:49P

To (figure 2)

    date_id    employee_id    time_in     time_out
      1            3           1:00P        2:00P
      2            2           3:20P        3:49P
      3            2         > 5:10P        6:29P <

But what happen is, it goes back to figure 1 again. Over writing all fields with the same value as employee_id. Any other ways of doing this?

The query I used:

UPDATE 'attendance' SET time_out = ? WHERE employee_id = ?

Yes I'm making simple Time In and Time Out application(Java).

[SOLVED My problem] but not the question, there is no way to update it using 'employee_id'.

Answers


chalitha lawanga February 2016

Use the primary key to identify the exact row, If you do not have a primary key try this way:

UPDATE 'attendance' SET time_out = ? WHERE employee_id = ? AND date_id=?


romanoza February 2016

As chalitha lawanga said, but a little simpler:

UPDATE 'attendance' SET time_out = ? WHERE date_id = ?

If date_id is a PK, then employee_id is not needed in your statement.

Post Status

Asked in February 2016
Viewed 2,277 times
Voted 7
Answered 2 times

Search




Leave an answer