作者luo74128 (小猫)
看板PHP
标题[请益] MYSQL 不重复新增资料
时间Sat Jul 30 15:59:45 2011
大大们请问一个问题我想要新增一笔资料
但想设个条件,假如栏位1与栏位2都相同的话,代表重复项
因此不可以新增此笔资料。
以下是我写的SQL 但总是出错,烦请各位大大指导一下。
INSERT INTO power (`Id`,`Account`,`Form`)VALUES('','root','123')
WHERE not exists
(SELECT * FROM power WHERE `Account` = 'root' AND `Form`='123')
MySQL 传回:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE not exists
(SELECT * FROM power WHERE `Account` = 'root' AND `Form`='123'' at line 2
--
Aman ia vida 地下飞行
blog:
http://luo74128.blogspot.com/2010/07/blog-post.html
我:
http://www.wretch.cc/album/luo74128
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 202.134.88.79
1F:推 tn801534:旧版mysql?不能子查询? 查一下版本吧 07/30 16:35
2F:→ arrack:INSERT INTO 不能直接接where 07/30 18:53
4F:→ averywu:INSERT .... ON DUPLICATE KEY UPDATE 07/31 22:31
5F:推 yukang:设 uniq index 不是比较好嘛?也不用每次都塞 08/01 08:16