[英]Update a column in MySQL table if only the values are empty or NULL
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... ie 现在我想使用相同的查询添加一个条件...即
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;
? ?
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;
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 ='';
Try this code SQL native it's work for me very well : 试试这段代码SQL native它对我很有用:
UPDATE table
SET field = 'New value'
WHERE field
IS NULL
OR field = ''
Update just NULL value or EMPTY . 仅更新NULL值或EMPTY 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.