我想要一个解决方案来插入一条记录,如果它不存在,所以我在这里搜索并找到了一个解决方案,但我还有另一个问题
INSERT INTO closed_answers (question_id, subject_id)
SELECT * FROM (SELECT 2, 2) AS tmp
WHERE NOT EXISTS (
SELECT question_id FROM closed_answers WHERE question_id = 2 AND subject_id = 2
) LIMIT 1
输出是
#1060 - Duplicate column name '2'
如果我使用了任何 2 个不相同的数字,它会起作用,但是当 2 个数字相同时就会出现问题