|
Prev: how to use SUM [RESOLVED]
Next: Database is in Transistion. There is already an open datareader associated with this data
From: Steve Kass on 22 Jul 2008 14:11 Mufasa, In SQL Server 2005, it's not hard: with T as ( select *, row_number() over ( partition by your_unique_key order by their_unique_key ) as occurence from theTable ) select <columns you want> from T where occurence = 1 This selects the first occurrence in their-key order of each customer (as defined by your-key). Steve Kass Drew University http://www.stevekass.com Mufasa wrote: >I've got a list of customers, customer names, ... from another db (I didn't >design it). > >I want to get a list of all of the customers plus the first customer name. >So if customer 1 appears twice (customer name = 'Fred' and 'John') I want >the first one it finds. > >Is there an easy way to do this without spinning through all of the records. >I'm using the results of the query as a select statement as input to an >insert statement. > >TIA - Jeff. > > > > |