Sunday, February 19, 2012

Delete Records Which had some duplciate columns

I had the table with 5 columns and many rows.
Now i want to delete the records which meets column1,column2,column3 are same and keep one record on it.

Create Table T1 (Number int,name1 varchar(25), name2 varchar(25), name3 varchar(25), name4 varchar(25) )

Insert Into T1 values(1,'aaa','bbb','ccc','dd1')
Insert Into T1 values(1,'aaa','bbb','ccc','dd1')
Insert Into T1 values(1,'aaa1','bbb','qqq','ttt')
Insert Into T1 values(2,'www','xxx','yyy','zzz')
Insert Into T1 values(2,'www','xxx','nnn','mmm')
Insert Into T1 values(2,'www2','xxx','nnn','mmm')
Insert Into T1 values(3,'fff','ggg','hhh','iii')
Insert Into T1 values(3,'fff','ggg','rrr','lll')

Result shall be

1-aaa-bbb-ccc-dd1
1-aaa1-bbb-qqq-ttt
2-www-xxx-yyy-zzz
2-www2-xxx-nnn-mmm
3-fff-ggg-hhh-iiii didnt understood u completely, but what i see is that just 1st and 2nd row are same.
so instead of
select * from t1
u can
select distinct * from t1
so then u will have one row instead of two row for first two insert.|||

Quote:

Originally Posted by hisham123

I had the table with 5 columns and many rows.
Now i want to delete the records which meets column1,column2,column3 are same and keep one record on it.

Create Table T1 (Number int,name1 varchar(25), name2 varchar(25), name3 varchar(25), name4 varchar(25) )

Insert Into T1 values(1,'aaa','bbb','ccc','dd1')
Insert Into T1 values(1,'aaa','bbb','ccc','dd1')
Insert Into T1 values(1,'aaa1','bbb','qqq','ttt')
Insert Into T1 values(2,'www','xxx','yyy','zzz')
Insert Into T1 values(2,'www','xxx','nnn','mmm')
Insert Into T1 values(2,'www2','xxx','nnn','mmm')
Insert Into T1 values(3,'fff','ggg','hhh','iii')
Insert Into T1 values(3,'fff','ggg','rrr','lll')

Result shall be

1-aaa-bbb-ccc-dd1
1-aaa1-bbb-qqq-ttt
2-www-xxx-yyy-zzz
2-www2-xxx-nnn-mmm
3-fff-ggg-hhh-iii


i think you have to search before posting, there lot of Querys are here.

No comments:

Post a Comment