update on duplicate without primary key
Moderator: General Moderators
update on duplicate without primary key
the entries in my database do not have unique identifiers or a key, to identify entries they are selected by 'name' and by 'group' it makes the assumption that there is not more then one person who has the same 'name' and 'group', it would be a headache to add unique identifiers for each entry because my php code pulls the data for the database from an external source which does not supply unique identifiers. so what im looking for is a simplistic and streamlined way of inserting entries into the database but if there exists an entry with the same name and group, update that entry instead of adding a new entry. i know i could do a search in the database for that name and group and if it finds anything then do an update otherwise do an insert, does anyone know if there is a method of doing this in one statment, something like "ON DUPLICATE KEY" however without a key more like "UPDATE .... WHERE *where clause* OR (if no matching where) INSERT"
Re: update on duplicate without primary key
You don't need a surrogate PK like ID's - you should use a composite natural PK - (name, group).
There are 10 types of people in this world, those who understand binary and those who don't