Update where count > 1
-
Hi, How do you write a SQL statement to update records if the count of a field is greater than 1? Thanks
update mytable set column='value'
where id in (select id from mytable group by id having (count(id)>1))Hope it will help you.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com
-
Hi, How do you write a SQL statement to update records if the count of a field is greater than 1? Thanks
Somebody has been kind enough to foresee such question; have a look here[^]. FYI: I found the link by Googling SQL update EDIT unless count isn't the name of a field, and you intended to count some rows and use that as a selection criterium... Then look at the other reply. /EDIT :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
modified on Tuesday, August 24, 2010 4:23 PM
-
Hi, How do you write a SQL statement to update records if the count of a field is greater than 1? Thanks
try something like this ...
Update myItems set myField = 'more than 1 count' where item_class in ( select item_class from myItems group by item_class having count(*) > 1 )
-
try something like this ...
Update myItems set myField = 'more than 1 count' where item_class in ( select item_class from myItems group by item_class having count(*) > 1 )
-
Then mark as answer. :-)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com