There is a table to which views are added. So if there is an entry in the table with these users, you should NOT add an entry but change the existing one. Sample trigger code:

CREATE TRIGGER before_insert_view BEFORE INSERT ON ad_views FOR EACH ROW BEGIN SET @idExists = (SELECT ad.id FROM ad_views av WHERE av.ip_address = NEW.ip_address AND av.ad_id = NEW.ad_id); IF @idExists THEN UPDATE ad_views av SET av.quantity = av.quantity + 1; //ΠžΡ‚ΠΌΠ΅Π½ΠΈΡ‚ΡŒ добавлСния Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ записи; ELSE //ВсС Π½ΠΎΡ€ΠΌΠ°Π»ΡŒΠ½ΠΎ, ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ запись; END IF; END; 
  • It did not work with mysql, but in postgresql you can do this: RETURN NULL; - when not to write. - aleks.andr
  • @ aleks.andr I tried to do this, but the error crashes that RETURN is allowed only in functions - Shuhratjon Jumaev
  • Then create a trigger function, which will be RETURN NULL . From the trigger, call it. - aleks.andr
  • 2
    Is it possible to use the ON DUPLICATE KEY UPDATE construct? - Venta
  • one
    On MySQL, you do not solve such a task with triggers. Use insert on duplicate key or replace - Mike

0