插入记录(如果不存在) [英] insert a record if not exist
问题描述
大家好,
我对mysql中的WHERE NOT EXISTS感到困惑.我在php编辑器中使用了以下语法:我想将记录从一张表(一段时间内)一张一张地插入到tmp表中,并且我想在插入之前检查网址是否存在于tmp中,或者如果不存在,我不想如果不存在,我将插入它,这是我最终得到的代码!!但是即使tmp表为空,它也不会插入....任何建议吗?
-非常感谢
$ INSERT_SQL =(插入到tmp(company_name,link)
SELECT($ comp_name,$ url)不存在(SELECT * FROM TMP WHERE link = $ url));
$ result2 = mysql_query($ INSERT_SQL,$ con);
Hi ALL,
I am kind of confused with the WHERE NOT EXISTS in mysql. I used this syntax in php editor: I want to insert records one by one from one table (in a while) to a tmp table and I want to check before inserting if the url is exists in tmp or not if exists I dont want to insert if not exist I wnat to insert this is a code I end up with it!!!but It doesnt insert even when the tmp table is empty....any suggestion?
-Many thanks
$INSERT_SQL=(INSERT INTO tmp (company_name,link)
SELECT ($comp_name,$url) WHERE NOT EXISTS (SELECT * FROM TMP WHERE link=$url));
$result2 = mysql_query($INSERT_SQL,$con);
推荐答案
INSERT_SQL =(INSERT INTO tmp(company_name,link)
SELECT(
INSERT_SQL=(INSERT INTO tmp (company_name,link)
SELECT (
comp_name,
comp_name,
url)不存在(SELECT * FROM TMP WHERE link =
url) WHERE NOT EXISTS (SELECT * FROM TMP WHERE link=
这篇关于插入记录(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!