So i have this two tables, the operators_payments AS op is populated with data, but the op.date_paid will be NULL, till payment date arrives, when this happens, the payment_process AS pp table is used to initialize the payment (pp.date_started is set to NOW()), then for payment completion the op.date_paid is set to pp.date_started. The shown query, is used to do this, all is good, but when all records are updated, one of the records and only one gets the op.date_paid with different time, specifically the second part e.g.(time set to all but one: 2012-07-05 17:28:14, time set to one: 2012-07-05 17:28:02).
Im using Mysql 5.5, the columns have the same type (TIMESTAMP).
I need this because i need the date to be exact as the one in pp.date_started.
My question is, Why does this happens, and what can i do to have this as espected?
UPDATE operators_payments AS op
JOIN payment_process AS pp
ON op.operator_id = pp.operator_id
AND pp.type = 0
AND pp.status = 1
SET op.date_paid = pp.date_started, pp.status = 2, pp.message=CONCAT(SUBSTRING_INDEX(message, '|', 1), '| was completed successfully!')
WHERE op.operator_id = {$this->operator_id}
AND op.date_paid IS NULL
AND op.date_end <= pp.date_accounted
+---------------+-----------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-----------------------+------+-----+-------------------+----------------+
| payment | int(10) unsigned | NO | PRI | NULL | auto_increment |
| operator_id | int(10) unsigned | NO | MUL | 0 | |
| date_paid | timestamp | YES | MUL | NULL | |
| date_start | timestamp | YES | | NULL | |
| date_end | timestamp | YES | MUL | NULL | |
| amount | decimal(6,4) unsigned | NO | | 0.0000 | |
+---------------+-----------------------+------+-----+-------------------+----------------+
+----------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+-------------------+-----------------------------+
| operator_id | int(11) | NO | PRI | NULL | |
| type | tinyint(4) | NO | PRI | NULL | |
| date_started | timestamp | YES | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| date_accounted | timestamp | YES | | NULL | |
| amount | decimal(6,4) | YES | | NULL | |
| status | tinyint(4) | YES | MUL | 0 | |
| message | varchar(255) | YES | | NULL | |
+----------------+--------------+------+-----+-------------------+-----------------------------+
I have a suspicious eye toward that
on update CURRENT TIMESTAMPclause on the date_started on payment_process… I’m not actually sure what it could be doing in this query, but you are updating that table in this query, and using that value. I also don’t like the semantic discord of a column calleddate_startedwhich has it’s value changed on every update… but I don’t know how it’s used. I would evaluate if that clause is necessary on that column, and see if you get this strange behavior without it,