-------------------------------
-- Use two EXISTS:
-------------------------------
UPDATE tblCustomer tc
SET type = 2
WHERE EXISTS (
SELECT *
FROM tblorder ex
WHERE ex.fidcustomer1 = tc.idcustomer
)
OR EXISTS (
SELECT *
FROM tblorder ex
WHERE ex.fidcustomer2 = tc.idcustomer
);
-------------------------------
-- or combine the two EXISTS::
-------------------------------
UPDATE tblCustomer tc
SET type = 2
WHERE EXISTS (
SELECT *
FROM tblorder ex
WHERE ex.fidcustomer1 = tc.idcustomer
OR ex.fidcustomer2 = tc.idcustomer
);
My gut feeling is that the first version (with two separate exists) will perform better, because the executor could short-circuit if one of the existss would yield True
. That would avoid the removal-of-duplicates phase (and probably sorting), which is inherent to the UNION construct.