插入如果不存在mysql 5.5.24

时间:2012-10-02 00:04:59

标签: mysql

我一直在四处寻找,但是我看不出我的错误,

我的查询

INSERT INTO p_location_check (location_id) VALUES (1) 
IF NOT EXISTS (SELECT approved, disapproved FROM p_location_check WHERE approved REGEXP '^1234568745$' OR disapproved = '^1234568745$' AND location_id=1); 

仅用于测试

INSERT INTO p_location_check (location_id) VALUES (1) 
IF NOT EXISTS (SELECT approved, disapproved FROM p_location_check WHERE approved = 1234568745 OR disapproved = 1234568745 AND location_id=1);

效应初探

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   'IF NOT EXISTS附近(选择批准,不批准来自   qp_location_check WHERE批准'第2行

服务器版

  

服务器版本:5.5.24-0ubuntu0.12.04.1

1 个答案:

答案 0 :(得分:0)

<强>编辑:

尝试此查询 -

INSERT INTO p_location_check (location_id) VALUES (1) FROM dual
WHERE (SELECT COUNT(*)
       FROM p_location_check
       WHERE approved = 1234568745 OR disapproved = 1234568745 AND location_id=1
       ) = 0;

添加您的WHERE条件。