i am trying to update a table by setting column VAT TO 2 where we have duplicate values in column image
SET
VAT = 2
WHERE id >0
HAVING count(image) > 1
i am trying to update a table by setting column VAT TO 2 where we have duplicate values in column image
SET
VAT = 2
WHERE id >0
HAVING count(image) > 1
You could do this:
UPDATE applicantinfo
SET VAT = 2
WHERE image IN (
SELECT image
FROM (SELECT * FROM applicantinfo)
WHERE id > 0
GROUP BY image
HAVING COUNT(*) > 1
)
SELECT
inside the WHERE
clause supplies duplicate image
s of rows with id
s above zero.
You may use this.
For SQL Server
update t set t.VAT = 2 from applicantinfo as t inner join
(select Image from applicantinfo group by image having count(*)>1) as b
on t.image = b.image
From your comment to a previous answer I assume that you use MySql.
In MySql you need to join the table to a query that returns the duplicate images:
update tablename t inner join (
select image
from tablename
where id > 0
group by image
having count(*) > 1
) i on i.image = t.image
set vat = 2;