I need to do a simple update operation on some columns in a join table on my DB, however, I do not want to make the update if a column with the updated value already exists.
So say the join table looks something like this:
_id | fkId
----------
1 | A
1 | B
2 | B
3 | C
3 | B
4 | A
- I want to update all the entries that have the
fkIdofB, toA - However, each entry must be unique, so if I already have another entry for that same
_idalready set tofkIdA, then I don't want to do the update but instead just get rid of it
My update currently looks like the following:
UPDATE my_table
SET "fkId"='A'
WHERE "fkId"='B';
In my example table above you see entry of _id 1, so if I run this query I will end up with two entries as
_id | fkId
----------
1 | A
1 | A
I do not want this. Each pair needs to be unique, so it must be deleted. How can I have this happen through a query?