In sql table I select duplicate IDs which count is > 1 .Then I need to update only first row of selecting duplicate id rows.How to update just first row value. Thanks in advance.
Asked
Active
Viewed 1,138 times
0
-
1A) "First" is undefined in SQL. You'll at least need to have a sort order in mind. B) You probably shouldn't have duplicate IDs, assuming the "ID" is supposed to be the primary key. Also, it would be helpful if you could include what flavour of SQL you're using. – Michelle Aug 12 '13 at 13:35
-
I might be wrong, but it feels like [this question](http://stackoverflow.com/questions/1513206/update-multiple-rows-using-limit-in-mysql) is very similar to yours. – Nicolas Rinaudo Aug 12 '13 at 13:44
-
Hello Flavour is MSql 2008 r2.These IDs is in VIEW.because of it they are duplicate. – user2675096 Aug 12 '13 at 13:50
1 Answers
0
Assuming you have something like this:
SELECT ID
FROM ProductView
GROUP BY ID
HAVING COUNT(*) > 1
You will need to create a loop around the query and then select a result using TOP 1 and matching the ID. You can create the loop using a cursor.

Jim Stevenson
- 139
- 1
- 2