Mysql update different fileds set depend on condition
I like the JOIN syntax, it's clearer to me than subqueries:

UPDATE a LEFT JOIN b ON (a.ib=b.i) 
SET i1 = j1, 
    i2 = if(isnull(b.i), j2 ,i2) 
WHERE a.id = jid;


This will change the jid record: i1 to j1 always and i2 to j2 if no match exists, and to the same value if the match exists. You may want to index b.i (probably as a primary key) if there are a lot of records and you want performance.