-3

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?

Martin AJ
  • 6,261
  • 8
  • 53
  • 111

2 Answers2

0

try this way

Using IFNULL()

UPDATE users u SET events = IFNULL(events, 0) + 1 WHERE id u.id = new.user_id;
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
0

Use COALESCE() function regard a NULL as a 0

UPDATE users u SET events = COALESCE(events, 0) + 1 WHERE u.id = new.user_id;
Kickstart
  • 21,403
  • 2
  • 21
  • 33