0

I have a table that stores 3 values one being the primary key.

table_id, site_id, contract_id

enter image description here

Values are sent from a html form, I need to add more values per site_id.

If I post values that don't already exist then it's not a problem obviously.

However the form will post the existing values as well

Example

1, 1, 1;
2, 1, 2;
3, 1, 3;
4, 1, 4;

To insert those I currently have to delete all where site_id = 1; this is so that I don't have duplicates in the table.

Is there another efficient way to do this? I can make those composite keys to avoid duplicates but I think I will have to handle errors in that way?

RamC
  • 1,277
  • 1
  • 10
  • 15
Abu Nooh
  • 756
  • 3
  • 10
  • 36
  • Yes please close it, although the linked question has a solution it was slightly different than mine as my values were duplicate including non-primary keys. But found the solution. – Abu Nooh Dec 17 '17 at 19:56
  • Used insert ignore. Having created composite keys. But thanks – Abu Nooh Dec 17 '17 at 23:00

0 Answers0