Jump to content

Unsure on SQL for INSERT... ON DUPLICATE UPDATE with two columns


nemovc

Recommended Posts

Hi

 

I have a table 'contributions'

 

CREATE TABLE `op_contributions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `attachID` int(11) NOT NULL,
  `playerID` int(11) NOT NULL,
  `a` int(11) NOT NULL,
  `b` int(11) NOT NULL,
  `c` int(11) NOT NULL,
  `d` int(11) NOT NULL,
  `e` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1

 

The playerID is the ID (primary key) of a row in another table (players), and the attachID is the ID (primary key) of a row in another table (plans). (a to e are data fields).

 

attachID and playerID don't have to be unique, but the combination of them has to be. E.g., there are many different plans, and each has a different players contributing different amounts, but each player can only contribute once to each plan.

 

I am unsure how to create a INSERT ... ON DUPLICATE UPDATE query when it is the combination of two columns that is important, not a singular column.

 

(At the moment I am using the messy workaround of loading the all the plans into php and then either UPDATE or INSERT depending on if a record is already found)

 

Response greatly appreciated :)

Link to comment
Share on other sites

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.