I select a value into a mysql variable. Eg...
select @userId := userId
from myTable
where id = ?;
The value of @userId may be null.
Now I want to update the rows in another table based on the value of @userId.
Simply stating "where userId = @userId" will not always work, since "userId = null" will never come back true in mysql, even if userId is null.
The following statement appears to work fine instead...
update myOtherTable
set something = "something"
where (
userId = @userId or
(@userId is null and userId is null)
);
...however I just wanted to run this by the gurus here, to make sure it is mostly "okay". (Evaluating a variable apart by itself in the where clause feels a bit strange to me.)
Thoughts?