如何在插入行mysql时使用如果不存在的话 [英] how to use if not exists while inserting a row mysql

查看:88
本文介绍了如何在插入行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.

这篇关于如何在插入行mysql时使用如果不存在的话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆