bananamana
bananamana

Reputation: 515

MySQL INSERT on condition

I have a table user_has_alerts (userID, alertID, dateAlerted) and i'm trying to update all NULL values in dateAlerted field for a given user to the current date. Any help would be much appreciated.

Upvotes: 0

Views: 208

Answers (2)

Jeff Swensen
Jeff Swensen

Reputation: 3573

UPDATE user_has_alerts SET dateAlerted = CURDATE() 
 WHERE userID = X AND dateAlerted IS NULL

Upvotes: 2

Headshota
Headshota

Reputation: 21449

UPDATE `user_has_alerts` SET `dateAlerted` = NOW() WHERE `dateAlerted` IS NULL AND userID = 1

Upvotes: 1

Related Questions