Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select distinct and delelete duplicates

Author  Topic 

kote_alex
Posting Yak Master

112 Posts

Posted - 2008-12-12 : 04:43:07
I have a table with 18000 rows but only 16400 are distinct... How can I delete the duplicates?

Thanx !

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-12 : 04:49:30
Hi, Please post your table structure...
Go to Top of Page

kote_alex
Posting Yak Master

112 Posts

Posted - 2008-12-12 : 04:59:45
Columns : Number of order(PK,int,not null ); bill HB(int,null) ; unique identity(nchar(10),null) ; Bill number(int,null) ; user(nchar(30),null); date/hour(datetime,null).


the disctinct criteria is BILL HB column... that the key
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-12-12 : 05:14:42
hi try this

DELETE FROM your_table WHERE Numberoforder not in ( select max(Numberoforder) from your_table group by billHB)

ok tanx.......
Go to Top of Page

kote_alex
Posting Yak Master

112 Posts

Posted - 2008-12-12 : 05:21:17
quote:
Originally posted by soorajtnpki

hi try this

DELETE FROM your_table WHERE Numberoforder not in ( select max(Numberoforder) from your_table group by billHB)

ok tanx.......




It did it !!!

Thax !!!
Go to Top of Page
   

- Advertisement -