To avoid updating the original row and to know which is the first row, you'll need some kind of row identifier (a primary key) If you have one, the query isn't too complex, you'll join your original query with the table and use IF
(or CASE
) to find and update the matches;
UPDATE tablea a1
JOIN (
SELECT * FROM TableA WHERE P1!=0 OR P2!=0 OR P3!=0 OR P4!=0 ORDER BY id LIMIT 1
) a2
ON IF(a2.p1, a1.p1, 1) AND IF(a2.p2, a1.p2, 1) AND
IF(a2.p3, a1.p3, 1) AND IF(a2.p4, a1.p4, 1) AND a1.id<>a2.id
SET a1.p1=IF(a2.p1, 0, a1.p1), a1.p2=IF(a2.p2, 0, a1.p2),
a1.p3=IF(a2.p3, 0, a1.p3), a1.p4=IF(a2.p4, 0, a1.p4);