有時候需要檢查資料是否重複再填入,這裡簡單做個筆記。
程式碼
INSERT INTO `table` (`title`, `url`, `photocount`, `uploadtime`, `findtime`) SELECT @title, @url, @photocount, @uploadtime, @findtime FROM DUAL WHERE NOT EXISTS ( SELECT 1 FROM `table` WHERE `title` = @title AND `url` = @url);
SELECT @title, @url, @photocount, @uploadtime, @findtime
SELECT
後面是準備填入的參數
WHERE NOT EXISTS ( SELECT 1 FROM `table` WHERE `title` = @title AND `url` = @url);
WHERE
這邊驗證資料是否重複