Jump to content

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']
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.