作者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
推 tn801534:舊版mysql?不能子查詢? 查一下版本吧 07/30 16:35
→ arrack:INSERT INTO 不能直接接where 07/30 18:53
→ averywu:INSERT .... ON DUPLICATE KEY UPDATE 07/31 22:31
推 yukang:設 uniq index 不是比較好嘛?也不用每次都塞 08/01 08:16