delete from x where x.id in (select x.id from x group by x.id having count (*) > 1)
Main Topics
Browse All TopicsHow to Delete duplicate rows in a ms sql table?
kindly give me the query
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
select tranno from tblcardtransactions where tblcardtransactions.id in (select tblcardtransactions.id from tblcardtransactions group by tblcardtransactions.id having count (*) > 1)
Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'id'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'id'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'id'.
tranDateTime datetimeno 8 no (n/a) (n/a)
storeNo smallint no 2 5 0 no (n/a) (n/a)
tranNo smallint no 2 5 0 no (n/a) (n/a)
tillNo smallint no 2 5 0 no (n/a) (n/a)
cashierNo int no 4 10 0 no (n/a) (n/a)
tranType char no 1 no no no
cardNo decimal no 9 16 0 no (n/a) (n/a)
cardIssue tinyint no 1 3 0 no (n/a) (n/a)
itemCount smallint no 2 5 0 no (n/a) (n/a)
tranValue money no 8 19 4 no (n/a) (n/a)
SDValue money no 8 19 4 no (n/a) (n/a)
What the mining of duplication in this table? can you show two duplicates records? all values should be the same in order to say it is duplication? if yes then:
select tranDateTime, storeNo, tranNo, tillNo, cashierNo, tranType, cardNo, cardIssue, itemCount, tranValue,SDValue
into tempTable
from tblcardtransactions
group by tranDateTime, storeNo, tranNo, tillNo, cashierNo, tranType, cardNo, cardIssue, itemCount, tranValue,SDValue
having count (*) = 1
delete from tblcardtransactions
insert into tblcardtransactions
select * from tempTable
commit
Yes, creating id column (auto number) that will be used as a key
ALTER TABLE tblcardtransactions
ADD id INTEGER AUTONUMBER;
then using the following:
delete from tblcardtransactions where tblcardtransactions.id in
(select max(id)
from tblcardtransactions
group by tranDateTime, storeNo, tranNo, tillNo, cashierNo, tranType, cardNo, cardIssue, itemCount, tranValue,SDValue
having count (*) > 1)
Check here also , i have posted another question related to this , i got the query ..to do this using cursor ..please see
http://www.experts-exchang
I don't understand, what do you consider duplication?
Currently transdatetime is unique or not?
As long that the duplicated records are identical in all their columns then no other option.
The curser in your other question is an oracle cursor and uses rownum condition that does not exists in sql server. There is no way to delete one of the records since we don't have uniquness to use in the condition.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-01-08 at 01:32:27ID: 23323277
please specify which database/version you are working with, and what columns your table has, and how do you determined duplicate rows.