-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
forpas
  • 145,388
  • 9
  • 31
  • 69
meetmec12
  • 29
  • 6

3 Answers3

0

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 images of rows with ids above zero.

Sergey Kalinichenko
  • 697,062
  • 78
  • 1,055
  • 1,465
0

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

DarkRob
  • 3,737
  • 1
  • 8
  • 27
0

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;
forpas
  • 145,388
  • 9
  • 31
  • 69