Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Select and Identity Column

Author  Topic 

Starting Member

2 Posts

Posted - 2006-02-06 : 09:03:32
I had posted a question last week about about a getting rid of duplicates in a select statement that was answered thanks to people on this forum. After working on it I ran into a problem this weekend.

I have the following SQL statment that returns the correct number of rows

select Distinct CustomerName,CustomerNumber,SalesmanName,Min(ItemDescription) AS ItemDescription,OrigionalDateofService,InsuranceCarrier, Diag1,Diag2,Diag3,Diag4 from O2
Group By

The problem that I run into is that my O2 table also has and ID column, an auto Identity field, that must be included within the result set for development reasons.

When I add the ID to the select statement it returns all the rows of the column. What would be the correct way to include the ID field and get the right set of data.

Premature Yak Congratulator

22864 Posts

Posted - 2006-02-06 : 09:08:15
As auto Identity field is usually unique, you will get all records listed if you include that column in the select statement. If table has 10 rows and the select query returns 4 rows, then how do you expect the value of identity column? Do you want to assign a row number to the result set?


Failing to plan is Planning to fail
Go to Top of Page

- Advertisement -