0

So I'm trying to do a trigger in mySQL that looks like: on table:likes, event:after insert IF NEW.action` = 1 THEN

INSERT IGNORE INTO matches
(user_id, user_id_friend) 
(SELECT user_id_from, user_id_to
FROM likes
WHERE user_id_from = NEW.user_id_to AND user_id_to = NEW.user_id_from AND `action` = 1);

IF (SELECT user_id_from, user_id_to
    FROM likes
    WHERE user_id_from = NEW.user_id_to AND user_id_to = NEW.user_id_from
    AND `action` = 1) IS NOT NULL
    THEN

    INSERT IGNORE INTO matches
    (user_id, user_id_friend)
    VALUES
    (NEW.user_id_from, NEW.user_id_to);
END IF;

END IF`

the syntax should be right because heidi SQL (the software i'm using) allows me to save it, but when i try to insert something into likes with action = 1, it shows me: MySQL error 1241: Operand should contain 1 column(s) What am i doing wrong?

  • Try INSERT ON DUPLICATE instead (http://stackoverflow.com/questions/548541/insert-ignore-vs-insert-on-duplicate-key-update) – Ataboy Josef Feb 16 '15 at 12:03
  • worked that way: `IF NEW.`action` = 1 THEN INSERT IGNORE INTO matches (user_id, user_id_friend) (SELECT user_id_from, user_id_to FROM likes WHERE user_id_from = NEW.user_id_to AND user_id_to = NEW.user_id_from AND `action` = 1); IF (SELECT user_id_from FROM likes WHERE user_id_from = NEW.user_id_to AND `action` = 1) IS NOT NULL AND (SELECT user_id_to FROM likes WHERE user_id_to = NEW.user_id_from AND `action` = 1) IS NOT NULL THEN INSERT IGNORE INTO matches (user_id, user_id_friend) VALUES (NEW.user_id_from, NEW.user_id_to); END IF; END IF` – Никола Хилендаров Feb 16 '15 at 12:13

0 Answers0