SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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  

awanvil
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
CustomerName,
CustomerNumber,
SalesmanName,
OrigionalDateofService,
InsuranceCarrier,
Diag1,
Diag2,
Diag3,
Diag4

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.

madhivanan
Premature Yak Congratulator

India
22744 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?

Madhivanan

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-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000