szx248
asked on
Purging duplicate records?
I have a table with three fields:
Item varchar(4)
Customer varchar(4)
price smallmoney
sometimes there are more than one matching record. A matching record is when (item + customer) is the same.
Is there a way to eliminate all the duplicates besides for the last one. The last one would be the one that was added to the table last. This table is a temporary table with no indexes.
Item varchar(4)
Customer varchar(4)
price smallmoney
sometimes there are more than one matching record. A matching record is when (item + customer) is the same.
Is there a way to eliminate all the duplicates besides for the last one. The last one would be the one that was added to the table last. This table is a temporary table with no indexes.
ASKER
Very neat!
Now do I give the temporary table an identity column?
this is what my temporary table looks like:
CREATE TABLE #tempfile ( cus varchar(4), item varchar(4) , price smallmoney)
Now do I give the temporary table an identity column?
this is what my temporary table looks like:
CREATE TABLE #tempfile ( cus varchar(4), item varchar(4) , price smallmoney)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
awesome!
delete from #tempTable
WHERE i NOT IN (SELECT MAX(i) FROM #tempTable GROUP BY (item + customer) )