Monday, January 30, 2017

MYSQL Update From within the same table using some condition

MYSQL Update From within the same table using some condition


In Some cases, we need to update the table of one row with the values of the other row on the same table. Here is the query to do the same.
UPDATE patientinsurance dest
JOIN ( SELECT
patientCode,
policyNo
FROM
patientinsurance
WHERE
ID = 121590
) AS source

ON dest.patientCode = source.patientCode

SET dest.policyNo = source.policyNo
WHERE dest.id IN (121911)


Available link for download