MichaelS: SQL UPDATE out of SELECT

Beitrag lesen

I want to select all customers that have'nt written me in the last 3 years although I have writen them at least 5 times in the last 3 years.

So I built the folowing query:

SELECT KuIndex, Leben, Stubser FROM (SELECT Kontakte.KuIndex, MAX(IF(Kontaktart.Lebenszeichen = 1, Kontakte.Zeitpunkt, NULL)) AS Leben, SUM(IF(Kontaktart.Lebenszeichen IS NULL AND Kontakte.Zeitpunkt>DATE_ADD(CURDATE(), INTERVAL -3 YEAR), 1, 0)) AS Stubser FROM Kontakte INNER JOIN Kontaktart ON (Kontakte.Titel=Kontaktart.Kontaktart) GROUP BY Kontakte.KuIndex) Liste WHERE ((Stubser > 5) AND (Leben<DATE_ADD(CURDATE(), INTERVAL -3 YEAR)))

This query workes fine and shows all the customers suiting my affords.

As far - as good.

But now I want to SET the field Kunden.DeleteIntern of all this customers to 1. I've tried a few combinations like "UPDATE Kunden SET Kunden.DeleteIntern=1 WHERE (SELECT ...)" but everything causes an error.

Has anybody an idea how to add an UPDATE to my query?

regards Michael