Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | mparkhouseStarting Member
 
 
                                        5 Posts | 
                                            
                                            |  Posted - 2009-10-07 : 09:00:59 
 |  
                                            | I have the following in a table:ID        Category12345   Category 112345   Category 212345   Category 323456   Category 223456   Category 434567   Category 534567   Category 134567   Category 4I need a select statement that will pull the first ID/Category pair for each ID.I'm pretty sure there is a way to put a count on each of the records shown above into a temp table and then choose the records from the temp table with a count of 1.  However, I can't remember how to generate the count field.Any help would be greatly appreciated.Thanks,Mary |  |  
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2009-10-07 : 09:59:34 
 |  
                                          | Is this?select id,min(category) as category from tablegroup by idMadhivananFailing to plan is Planning to fail |  
                                          |  |  |  
                                    | mparkhouseStarting Member
 
 
                                    5 Posts | 
                                        
                                          |  Posted - 2009-10-07 : 10:02:21 
 |  
                                          | No, because I want the first one that was entered in the list and I'm not sure what the min() function would return with a varchar field.Thanks for answering. |  
                                          |  |  |  
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2009-10-07 : 10:09:39 
 |  
                                          | quote:Do you have any other unique column?MadhivananFailing to plan is Planning to failOriginally posted by mparkhouse
 No, because I want the first one that was entered in the list and I'm not sure what the min() function would return with a varchar field.Thanks for answering.
 
 |  
                                          |  |  |  
                                    | mparkhouseStarting Member
 
 
                                    5 Posts | 
                                        
                                          |  Posted - 2009-10-07 : 10:18:55 
 |  
                                          | Yes, there is a sequence number for each record which is unique. |  
                                          |  |  |  
                                    | senthil_nagoreMaster Smack Fu Yak Hacker
 
 
                                    1007 Posts | 
                                        
                                          |  Posted - 2009-10-07 : 10:25:21 
 |  
                                          | quote:sequence number is a auto generated id?? show samples!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/Originally posted by mparkhouse
 Yes, there is a sequence number for each record which is unique.
 
 |  
                                          |  |  |  
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2009-10-07 : 10:35:38 
 |  
                                          | select t1.* from table as t1 inner join(select id,min(sequence_number) as sequence_number from tablegroup by id) as t2on t1.id=t2.id and t1.sequence_number=t2.sequence_numberMadhivananFailing to plan is Planning to fail |  
                                          |  |  |  
                                    | mparkhouseStarting Member
 
 
                                    5 Posts | 
                                        
                                          |  Posted - 2009-10-07 : 10:54:58 
 |  
                                          | Thanks!  The last one did it.  Using min() on the sequence number was the key.   |  
                                          |  |  |  
                                |  |  |  |