如果只有值为空或 NULL,则更新 MySQL 表中的列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10262896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:03:53  来源:igfitidea点击:

Update a column in MySQL table if only the values are empty or NULL

mysqlsqljoomla

提问by ricardo

I had previously applied this query...which works perfectly and was answered by one of the fellow members of this forum

我以前应用过这个查询......它完美地工作并且由该论坛的一位成员回答

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

Now i want to use the same query adding one more condition... i.e

现在我想使用相同的查询添加一个条件......即

Set a.user_id = b.id only if a.user_id is empty ,,

仅当 a.user_id 为空时才设置 a.user_id = b.id ,,

can i apply this :

我可以申请这个吗:

if a.user_id = '' SET a.user_id = b.id ;

如果 a.user_id = '' SET a.user_id = b.id ;

?

?

回答by Teja

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;

回答by Ankit Sharma

Use this

用这个

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

If id have null values too then use this-

如果 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 ='';

回答by MISSIRIA

Try this code SQLnative it's work for me very well :

试试这个代码SQLnative 它对我来说很好用:

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

Update just NULLvalue or EMPTY.

只更新NULL值或EMPTY