Peter Bushnell
Peter Bushnell

Reputation: 928

MySQL: Update field not working

This should be simple but I am missing something. The following is supposed to look in the game table and set winner_id to 9999 where the winner_id is NULL.

The query executes none of the records gets updated with 9999. The winner_id column is set to varchar 10.

UPDATE game 
SET winner_id = 9999 
WHERE winner_id = NULL LIMIT 1";

Upvotes: 0

Views: 53

Answers (2)

Chris
Chris

Reputation: 2952

= NULL will not work, use: IS NULL instead.

Upvotes: 1

juergen d
juergen d

Reputation: 204746

You have to use IS when comparing to NULL instead of =

UPDATE game 
SET winner_id = 9999 
WHERE winner_id IS NULL 
LIMIT 1

Because comparing to null results in unknown with =.

Upvotes: 0

Related Questions