仅在值为空或NULL时更新MySQL表中的列

yrefmtwq  于 2023-02-18  发布在  Mysql
关注(0)|答案(4)|浏览(164)

我以前申请过这个查询...它工作得很完美,并得到了这个论坛的一位同事的回答

UPDATE
    jos_jbjobs_jobseeker a
    INNER JOIN jos_users b ON a.email = b.email
SET
    a.user_id = b.id

现在,我想使用相同的查询,再添加一个条件...即
仅b.id当.user_id为空时,才设置.user_id = www.example.com,
我可以应用这个吗:
如果a.用户ID =“”设置a.用户ID =b.id;

gr8qqesn

gr8qqesn1#

UPDATE
    jos_jbjobs_jobseeker a
    INNER JOIN jos_users b ON a.email = b.email
SET
    a.user_id = b.id
WHERE a.id IS NULL OR LENGTH(a.id)=0;
nkoocmlb

nkoocmlb2#

用这个

UPDATE
    jos_jbjobs_jobseeker a
    INNER JOIN jos_users b ON a.email = b.email
SET
    a.user_id = b.id
WHERE a.id ='';

如果id也为空值,则使用以下内容-

UPDATE
    jos_jbjobs_jobseeker a
    INNER JOIN jos_users b ON a.email = b.email
SET
    a.user_id = b.id
WHERE a.id is null or a.id ='';
liwlm1x9

liwlm1x93#

试试这段代码SQLnative,它对我来说非常有用:

UPDATE table 
SET field = 'New value'
WHERE field 
IS NULL
OR field = ''

仅更新NULL值或EMPTY

zour9fqk

zour9fqk4#

UPDATE table SET feildname= IF(`fieldname` is null,'Entervalue',`feildname`) WHERE ....

相关问题