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.
| Author |
Topic |
|
rocknpop
Posting Yak Master
201 Posts |
Posted - 2010-06-10 : 00:58:35
|
| Hi,I am trying to find and delete duplicate records:CREATE TABLE A(ID INT IDENTITY(1,1),NAME VARCHAR(10));INSERT INTO A (NAME) VALUES('A');INSERT INTO A (NAME) VALUES('A');INSERT INTO A (NAME) VALUES('A');INSERT INTO A (NAME) VALUES('B');INSERT INTO A (NAME) VALUES('B');INSERT INTO A (NAME) VALUES('C');INSERT INTO A (NAME) VALUES('C');INSERT INTO A (NAME) VALUES('D');Running this query should give me the duplicate records that will be deleted:SELECT s1.ID,s1.NAME FROM A s1,A s2WHERE s1.NAME=s2.NAME AND s1.ID<s2.IDBut this query returns:ID NAME1 A1 A2 A 4 B6 CWhy is this giving a duplicate record for ID=1 NAME=A. This is happening for all rows where dup names have more than 2 records.Thanks--------------------Rock n Roll with SQL |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-06-10 : 01:29:32
|
| you query login is wrong!put a one more insert statement after "D"INSERT INTO A (NAME) VALUES('A');Check what happen!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
|
|
rocknpop
Posting Yak Master
201 Posts |
Posted - 2010-06-10 : 02:58:06
|
| Thanks Senthil but after adding another row I am getting this now:ID NAME1 A1 A2 A 4 B6 C1 A2 A3 AThere is something wrong in this query but not able to figure out the problem.--------------------Rock n Roll with SQL |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-06-10 : 03:11:28
|
quote: Originally posted by rocknpop Thanks Senthil but after adding another row I am getting this now:ID NAME1 A1 A2 A 4 B6 C1 A2 A3 AThere is something wrong in this query but not able to figure out the problem.--------------------Rock n Roll with SQL
Your query is totally wrong!Re-write the query as per the links!Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
rocknpop
Posting Yak Master
201 Posts |
Posted - 2010-06-10 : 05:20:35
|
| Ok thanks, I figured out the problem in my query.--------------------Rock n Roll with SQL |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-06-10 : 05:28:11
|
Welcome Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
|
|
|