简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM