如果matchid和videoset字段等於當前值,我將如何插入一行或更新一行? 這就是我迄今爲止的內容,我期望如果我在空表上運行這兩次,結果的3行應該是返回的總量。當我運行這個查詢兩次,它不會更新像以前一樣添加的3個記錄,查詢將簡單地添加另外3個結果。任何有關這方面的知識將受到高度讚賞。謝謝!INSERT ON DUPLICATE KEY
INSERT INTO videos (matchid, youtubecode, videoid, videoset) VALUES
(96, "Blahblahblah", '', '1'),
(96, "WEEEEEE", '', '2'),
(96, "glgkgklbgjbgklbj", '', '3')
on duplicate key update matchid=values(videoset) AND videoset=values(videoset)
/*Column Information*/
----------------------
Field Type Collation Null Key Default Extra Privileges Comment
----------- ------------ ----------------- ------ ------ ------- -------------- ------------------------------- ---------
matchid int(10) (NULL) YES MUL (NULL) select,insert,update,references
youtubecode varchar(300) latin1_swedish_ci NO (NULL) select,insert,update,references
videoid int(11) (NULL) NO PRI (NULL) auto_increment select,insert,update,references
videoset int(11) (NULL) YES MUL (NULL) select,insert,update,references
/*Index Information*/
---------------------
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
------ ---------- -------- ------------ ----------- --------- ----------- -------- ------ ------ ---------- ------- ---------------
videos 0 PRIMARY 1 videoid A 6 (NULL) (NULL) BTREE
videos 1 matchid 1 matchid A 2 (NULL) (NULL) YES BTREE
videos 1 videoset 1 videoset A 6 (NULL) (NULL) YES BTREE
您對數據庫中的字段有任何限制嗎? – wazy
你能告訴我們表格模式和主鍵嗎? – KaeL
使用表架構和主鍵編輯 –