Create Table A (Col1 Int, Col2 Int) Insert A Select 1, 2 Union All Select 1, 2 Union All Select 2, 5 Union All Select 3, 4 Union All Select 3, 4 Union All Select 1, 3 GO Select Distinct * From A GO Drop Table A --Result /* Col1 Col2 1 2 1 3 2 5 3 4 */
不是查询,我要的是删除重复的记录.最好是一条SQl
一条sql不会多条sql的 Select Distinct * into #b From A delete from A insert into A select * from #bDrop table #b
(Col1 Int,
Col2 Int)
Insert A Select 1, 2
Union All Select 1, 2
Union All Select 2, 5
Union All Select 3, 4
Union All Select 3, 4
Union All Select 1, 3
GO
Select Distinct * From A
GO
Drop Table A
--Result
/*
Col1 Col2
1 2
1 3
2 5
3 4
*/
Select Distinct * into #b From A
delete from A
insert into A select * from #bDrop table #b