Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete duplicates

Status
Not open for further replies.

damipera

Technical User
Dec 1, 2005
134
GB
hi guys, can you give me some advice how to write the SQL to delete the duplicates? thanks for any suggestion.


something like this

id----myWords----chkbox1----chkbox2----chkbox3
1------apple----------x
2------orange----------------------------------x
3------apple----------x
4------orange----------------------------------x
5------apple----------x
6------banana---------------------x
7------orange----------------------------------x
8------banana---------------------x
9------apple----------x


then after deleting the duplicates, to look like this table


id----myWords----chkbox1----chkbox2----chkbox3
1------apple----------x
2------orange----------------------------------x
6------banana---------------------x


note: x, is a ticked checkbox

 

SELECT MIN(ID) AS ID, myWords, chkbox1, chkbox2, chkbox3
INTO #TEMP001
FROM YOURTABLE
GROUP BY myWords, chkbox1, chkbox2, chkbox3

TRUNCATE YOURTABLE

INSERT INTO YOURTABLE
SELECT *
FROM #TEMP001


I love deadlines. I like the whooshing sound they make as they fly by
Douglas Adams
(1952-2001)
 
delete yourtable
where id not in (select min(id) from yourtable as test group by myWords)

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top