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.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Select and Identity Column
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 02/06/2006 :  09:03:32  Show Profile
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 - 02/06/2006 :  09:08:15  Show Profile  Send madhivanan a Yahoo! Message
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
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000