CREATE TRIGGER `Delivery` AFTER INSERT ON `pending` FOR EACH ROW BEGIN SET @index = NEW.`index`; SET @sms_count = (SELECT COUNT(*) FROM `pending` WHERE `index` = @index); INSERT INTO `delivery` SET `index` = @index, `countSMS` = @sms_count WHERE `index` = @index; END 

what am I doing wrong?

1064 - You have an error in your SQL syntax; check the syntax for your right syntax to use at line 4

    2 answers 2

    And it will work?

     CREATE TRIGGER `Delivery` AFTER INSERT ON `pending` FOR EACH ROW BEGIN INSERT INTO `delivery` ( `index`, `countSMS` ) SELECT NEW.`index`, COUNT(*) FROM `pending` WHERE `index` = NEW.`index`; END 
    • Comments are not intended for extended discussion; conversation moved to chat . - PashaPash ♦
    1. Do not use custom variables in the trigger ( @index , @sms_count ).

    2. The INSERT INTO does not allow the WHERE .

    • I try all the options, I just can’t find a solution to my, as I used to think, just problems. You need to use Mysql tools to create a table with general information about the list. When creating a mailing list, the n-th number of numbers with different time of sending is added to the table. So here you need to output to another table ('index', 'number', 'number of sms', 'start time', 'time of completion') start time = time of sending the first sms, time of completion = time of sending the last sms, count -in sms = number of records with a specific index. - Anton Burak