Is it possible to test for a values existence, and update if exists, insert if not?
I have the following table:
Where characterID/accountID is a key. Occasionally, I'll pull data from an API, and get up to 3 characterIDs (I will already have the accountID). Is it possible to test if the characterID/accountID combo exists, if it does, update the linkedOn with the current date, and if it doesn't, insert it? Or do I have to do 2 queries? Is it acceptable to try to insert the data, knowing it may already exist, and relying on the fact that characterID/accountID is a primary key to make sure no repeats get in?
CREATE TABLE IF NOT EXISTS `characters` (
`characterID` int(11) NOT NULL,
`charName` varchar(50) NOT NULL,
`accountID` int(11) NOT NULL,
`linkedOn` datetime NOT NULL,
PRIMARY KEY (`characterID`,`accountID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;