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

I previously applied this request ... which works great and was answered by one of the participants in 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 another condition ... i.e.

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

can i apply this:

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

?

+3
source share
3 answers
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;
+11
source

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 is null then 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 is null or a.id ='';
+1
source

SQL, :

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

NULL EMPTY.

+1

All Articles