1

我尝试从表中删除一行,但是当我尝试时出现错误:#1241 - Operand should contain 1 column(s)

我的查询是:DELETE FROM Posts WHERE idPosts = 6;

我不明白为什么我不能删除帖子(idPosts = 6 的帖子存在)

我的桌子上也有一个触发器:

CREATE TRIGGER post_delete_update_lastPost_topic after delete on Posts for each row
BEGIN
  UPDATE Topics SET lastPost = (SELECT *
                                FROM Posts
                                WHERE idTopic = old.idTopic
                                ORDER BY datePosts DESC
                                LIMIT 1)
  WHERE idTopics = old.idTopic;
END $$
4

2 回答 2

2

在您的触发器中,您正在执行一项操作SELECT *,而您应该只选择与 lastPost 对应的列。我想这就像SELECT postId

于 2012-05-07T16:14:17.747 回答
1

UPDATE Topics SET lastPost = ( SELECT * FROM Posts WHERE idTopic = old.idTopic ORDER BY datePosts DESC LIMIT 1) WHERE idTopics = old.idTopic;

SELECT * 正在返回几列,请尝试 SELECT ID

于 2012-05-07T16:15:26.227 回答