-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
  • 160,666
  • 10
  • 38
  • 76
meetmec12
  • 29
  • 6
  • i simply want to update VAT where there are duplicate values in image column – meetmec12 Sep 07 '19 at 09:58
  • Tag your question with the database that you are using. – forpas Sep 07 '19 at 09:58
  • What's `image`'s type? – Sergey Kalinichenko Sep 07 '19 at 09:59
  • Which [DBMS](https://en.wikipedia.org/wiki/DBMS) product are you using? "SQL" is just a query language, not the name of a specific database product. Please [add a tag](https://meta.stackoverflow.com/questions/388759/why-should-i-tag-my-rdbms) for the database product you are using `postgresql`, `oracle`, `sql-server`, `db2`, ... –  Sep 07 '19 at 10:00

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
  • 714,442
  • 84
  • 1,110
  • 1,523
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,843
  • 1
  • 10
  • 27
  • 3
    That's non-standard SQL. Please mention for which DBMS product this works –  Sep 07 '19 at 10:09
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
  • 160,666
  • 10
  • 38
  • 76