我试着用搜索引擎对于这个问题,但只能找到如何使用两个表来做到这一点,如下所示,MySQL的直接INSERT INTO与WHERE子句
INSERT INTO tbl_member
SELECT Field1,Field2,Field3,...
FROM temp_table
WHERE NOT EXISTS(SELECT *
FROM tbl_member
WHERE (temp_table.Field1=tbl_member.Field1 and
temp_table.Field2=tbl_member.Field2...etc.)
)
这个工作对一个场景,但是现在我的兴趣是上传数据直接来自程序本身,而不使用两个表。我想要的是上传不在表格中的数据。我曾在我的头上的SQL就像下面,
INSERT INTO tbl_member (SensorIdValue, DataTimeValue, DataInValue, IncompleteValue, SpiValue, InfoValue)
VALUES ('Sensor.org', '20121017150103', 'eth0','','','')
WHERE (SensorIdValue != 'Sensor.org'AND DataTimeValue != '20121017150103'AND DataInValue != 'eth0'AND IncompleteValue != ''AND SpiValue != ''AND InfoValue != '');
但它是错的..可我知道做这件事请的正确方式,非常感谢你:)
基于你想到的SQL,它看起来像你想插入一行到一个表中,如果它不存在。如果是这种情况,请看看这个问题/答案。 http://stackoverflow.com/questions/1361340/how-to-insert-if-not-exists-in-mysql – qsheets
查看此问题。它可能会有帮助。 http://stackoverflow.com/questions/2930378/mysql-replace-into-alternative – Dev
yeaaa thats exaclty是我需要il检查这些..非常感谢您的回复:) –