you can not guarantee the uniqueness if no primary key defined. at least comp primary key.You can either insert all the values you need into a temp table with unique identifier defined or change your table structure my example will let you insert history into a temp table with unique id defined.declare @t1 table(partid varchar(50),effectivedate date,amount money);declare @t2 table(partid varchar(50),partdescription varchar(100));insert into @t1 (partid, effectivedate, amount)values('partone', '03-31-2010',1.00),('partone', '04-01-2010',1.01),('partone', '04-01-2010',1.00),('parttwo', '03-31-2010',2.00),('parttwo', '04-01-2010',2.01),('partthree', '03-31-2010',3.00),('partthree', '04-02-2010',3.01),('partfour', '03-31-2010',4.00),('partfour', '04-01-2010',4.01),('partfour', '04-01-2010',4.02),('partfive', '03-31-2010',5.00),('partfive', '03-31-2010',5.01),('partfive', '03-31-2010',5.02),('partfive', '04-01-2010',5.03),('partsix', '03-31-2010',6.00),('partsix', '04-01-2010',6.01)insert into @t2 (partid, partdescription)values('partone', 'part one'),('parttwo', 'part two'),('partthree', 'part three'),('partfour', 'part four'),('partfive', 'part five'),('partsix', 'part six')declare @t1temp table(pid uniqueidentifier default newid(),partid varchar(50),effectivedate date,amount money);insert into @t1temp(partid, effectivedate, amount) select * from @t1;declare @t2temp table(pid uniqueidentifier default newid(),partid varchar(50),partdescription varchar(100));insert into @t2temp(partid, partdescription) select * from @t2;select distinct c.partid, c.partdescription, b.ttlamt from (select * from @t1temp z where pid in (select top 2 pid from @t1tempwhere partid = z.partidorder by effectivedate desc)) a join (select partid, sum(amount) as ttlamt from (select * from @t1temp z where pid in (select top 2 pid from @t1tempwhere partid = z.partidorder by effectivedate desc))bgroup by partid)b on a.partid = b.partidjoin @t2temp c on c.partid = a.partid;quote:
Originally posted by freakofworks
Sorry, how to find PK? I think there is a "hash" column that has unique values for each record.Thanks again for your response.