Jump to content

Help with INSERT IGNORE INTO


djones

Recommended Posts

I'm trying to insert unique data based on 2 fields. The product_id and the value_id combined should be unique. I'm not sure how to do this.

I have:

ID(primary key) -- not shown below

PRODUCT_ID(unique key)

VALUE_ID(unique key)

VARIATION_ID

 

I need product_id and value_id to be unique together. When I insert this data it only insert one row and I'm assuming it's because It's just looking at each unique fields by itself thus stopping at the next '37' insert. For example 37 and 11 should not insert twice, 37 and 3 ...etc

 

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '11', '4')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '3', '2')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '10', '4')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '3', '2')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '9', '4')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '5', '2')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '11', '4')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '5', '2')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '10', '4')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '5', '2')

INSERT INTO table (product_id, value_id, variation_id) VALUES ('37', '9', '4')

Link to comment
https://forums.phpfreaks.com/topic/209607-help-with-insert-ignore-into/
Share on other sites

If you use the IGNORE keyword' date=' errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.[/quote']

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.