sql创建记录,如果存在或更新

时间:2015-10-08 07:31:59

标签: mysql sql

这是我的sql语句来实现查询。

insert into courses(course_id,course_name,courses) 
values (1,"bet","3") 
where not exists(25,"admin","it")

1 个答案:

答案 0 :(得分:1)

您必须使用SELECT查询。

INSERT INTO courses (course_id, course_name, courses)
SELECT 1, "bet", "3"
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM courses
    WHERE course_id = 25 AND course_name = "admin" AND courses = "it"
)