Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I always seem to find what I need in previous threads without starting my own. I have started a couple but that's it..."

Geography

Where in the world do Tek-Tips members come from?
damipera (TechnicalUser)
13 Jun 12 8:22
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

dhulbert (TechnicalUser)
13 Jun 12 8:36

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)

simian336 (Programmer)
13 Jun 12 8:51
delete yourtable
where id not in (select min(id) from yourtable as test group by myWords)

Simi
markros (Programmer)
13 Jun 12 9:21

CODE

;with cte as (select *, row_number() over (partition by myWords order by ID) as Rn)

delete from cte where Rn > 1

PluralSight Learning Library

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close