September 28, 2011 at 1:31 am
Dear Sir,
I am in great trouble, I have a table which contain 100 fields. I want to distinct on first two fields and with full information of 100 fields.
How to solve the problem, Plz. help me.
Thanking You
Debasis Bag
September 28, 2011 at 1:48 am
So you only want one row returned for each unique combination of those two columns? How are you going to decide which row that will be when there's more than one in the table? Please provide table DDL in the form of a CREATE TABLE statement, sample data in the form of INSERT statements, and expected results.
John
September 28, 2011 at 6:16 am
Without the structure, this is just a guess, but couldn't you do a subselect to get the unique set of two columns and then join that to the rest of the table...hmmm.... No, that might not work if there are duplicate versions of those values. Ah, how about using row_number then order by the values and get the PK that matches THEN join that out to the rest of the table. That would work.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply