Here is my query:
UPDATE users u SET events = events + 1 WHERE id u.id = new.user_id;
The default value of event
column is NULL
. So my query won't affect (increase). How can I handle that?
Here is my query:
UPDATE users u SET events = events + 1 WHERE id u.id = new.user_id;
The default value of event
column is NULL
. So my query won't affect (increase). How can I handle that?
try this way
Using IFNULL()
UPDATE users u SET events = IFNULL(events, 0) + 1 WHERE id u.id = new.user_id;
Use COALESCE() function regard a NULL as a 0
UPDATE users u SET events = COALESCE(events, 0) + 1 WHERE u.id = new.user_id;