如何在插入行mysql时使用如果不存在的话
问题描述:
我想做的事情是检查是否存在同一行,以及是否不向表中插入新行.
The thing that i want to do is to check if there is a same row and if not to insert a new row to the table.
在这种情况下,我该如何使用if not exists
?
In that case, how can i use if not exists
?
INSERT INTO `facebook` (`ID`,`fb_id`,`label_id`,`page_ids`,`token`) VALUES (NULL,'". $session['id'] ."','$id','','". $access_token ."')
例如,在该查询中,我想检查是否存在具有相同label_id记录的行,否则,请执行该查询.
For example, in that query, i want to check if there is a row with the same label_id record and if not, execute that query.
有什么帮助吗?
谢谢
答
您可以使用INSERT IGNORE INTO ...
语法.使用此功能时,重复的键错误将被视为警告,并且该语句将在不插入受影响的行的情况下返回.
You can use the INSERT IGNORE INTO ...
syntax. When using this, duplicate key errors are treated as warnings and the statement will return without having inserted the affected row.