How to update column of duplicate row in SQL Server -


i have table tuser columns username, password, email, active.

i need set active column of duplicate rows 0. how can achieve this?

eg: table values are

username    password   email             active ----------------------------------------------- demo        demo       abc@gmail.com       1 demo        demo       abc@gmail.com       1 demo        demo       abc@gmail.com       1 

i need change value to

demo demo abc@gmail.com 1 

and other 2 rows should be

demo demo abc@gmail.com 0 demo demo abc@gmail.com 0 

once have primary key in table uniquely identifies each row, can use cte , approach weed out duplicates:

;with duplicates (     select         userid, username, password, email, active,         rownum = row_number() on (partition username, email order userid)             tuser ) update tuser set active = 0 duplicates d d.userid = tuser.userid   , d.rownum > 1 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -