RB Smissaert <[EMAIL PROTECTED]>
wrote:
How do I alter this SQL, so that the original field remains the same
when there is no match? A case when else end should do it, but I can't get it right.

UPDATE Table1 SET Field1 =
(SELECT Field2 FROM Table2
WHERE Table1.Field1 = Table2.Field1)

UPDATE Table1 SET Field1 =
IFNULL(
   (SELECT Field2 FROM Table2
    WHERE Table1.Field1 = Table2.Field1),
   Field1);

-- or

UPDATE Table1 SET Field1 =
(SELECT Field2 FROM Table2
    WHERE Table1.Field1 = Table2.Field1
 union all select Table1.Field1;
);

-- or

UPDATE Table1 SET Field1 =
   (SELECT Field2 FROM Table2
    WHERE Table1.Field1 = Table2.Field1)
where exists
   (SELECT Field2 FROM Table2
    WHERE Table1.Field1 = Table2.Field1)

Igor Tandetnik

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to