I need to do a query to update a column, but only update the column if the data to be updated does not currently exist in that column.
I need to do a query to update a column, but only update the column if the data to be updated does not currently exist in that column.
The ideal is to leave the field UNIQUE
, but if for some reason you need to do, you can use a query similar to this:
UPDATE
suatabela
SET
seucampo = 'seuvalor'
WHERE
seucampo NOT IN (SELECT
COUNT(seucampo)
FROM
suatabela
WHERE
seucampo = 'seuvalor')