Click here to Skip to main content
15,895,084 members
Home / Discussions / Database
   

Database

 
AnswerRe: handle transaction without deadlock Pin
Afzaal Ahmad Zeeshan1-Dec-15 5:20
professionalAfzaal Ahmad Zeeshan1-Dec-15 5:20 
GeneralRe: handle transaction without deadlock Pin
Richard Deeming1-Dec-15 5:37
mveRichard Deeming1-Dec-15 5:37 
QuestionHELP ME ADD EXCEPTION Pin
VicPat25-Nov-15 2:14
VicPat25-Nov-15 2:14 
AnswerRe: HELP ME ADD EXCEPTION Pin
Mycroft Holmes25-Nov-15 12:04
professionalMycroft Holmes25-Nov-15 12:04 
QuestionRemove Unique constraint from an Non-Clustered Index Pin
indian14324-Nov-15 6:26
indian14324-Nov-15 6:26 
QuestionStudent Grade and Grade Point Callculation Pin
Aliyu Usman21-Nov-15 11:50
Aliyu Usman21-Nov-15 11:50 
AnswerRe: Student Grade and Grade Point Callculation Pin
Mycroft Holmes21-Nov-15 13:41
professionalMycroft Holmes21-Nov-15 13:41 
GeneralRe: Student Grade and Grade Point Callculation Pin
Aliyu Usman21-Nov-15 19:07
Aliyu Usman21-Nov-15 19:07 
GeneralRe: Student Grade and Grade Point Callculation Pin
Mycroft Holmes21-Nov-15 20:47
professionalMycroft Holmes21-Nov-15 20:47 
AnswerRe: Student Grade and Grade Point Callculation Pin
GuyThiebaut24-Nov-15 2:08
professionalGuyThiebaut24-Nov-15 2:08 
Questionnewtonsoft.json parser - how to deploy a CLR to SQL Server 2008 R2? Pin
Member 822518018-Nov-15 11:55
Member 822518018-Nov-15 11:55 
QuestionRemoval and delete of duplicate records in my table Pin
goldsoft15-Nov-15 2:37
goldsoft15-Nov-15 2:37 
AnswerRe: Removal and delete of duplicate records in my table Pin
Mycroft Holmes15-Nov-15 11:53
professionalMycroft Holmes15-Nov-15 11:53 
AnswerRe: Removal and delete of duplicate records in my table Pin
RNA Team15-Nov-15 16:00
RNA Team15-Nov-15 16:00 
Try this

SQL
CREATE TABLE tblTest (ID INT, NAME VARCHAR(20),AGE INT)
INSERT INTO tblTest VALUES(1,'AAA',22),(1,'AAA',22),(2,'BBB',33),(2,'BBB',33),(2,'BBB',33),(3,'CCC',44),(4,'DDD',55)

--create an alternate table to store the duplicate records
CREATE TABLE tblTestDuplicate (ID INT, NAME VARCHAR(20),AGE INT)

-- insert those duplicate records to this new table
INSERT INTO tblTestDuplicate
SELECT *
FROM tblTest
GROUP BY ID,NAME,AGE
HAVING COUNT(ID) > 1

--delete the duplicate records from the original table
DELETE FROM
tblTest 
WHERE  ID IN (SELECT ID FROM tblTestDuplicate)

--insert all the records into the original table
INSERT INTO tblTest
SELECT * 
FROM tblTestDuplicate

--Project the new records
SELECT *
FROM tblTest
ORDER BY ID


--clean up
DROP TABLE tblTestDuplicate
DROP TABLE tblTest


/*
SQL
ID	NAME	AGE
1	AAA	    22
2	BBB	    33
3	CCC	    44
4	DDD	    55

*/

Hope this helps

modified 15-Nov-15 23:11pm.

QuestionI need to get a count of records, including column Names grouped by UnitName. What am I doing wrong? Pin
samflex13-Nov-15 5:34
samflex13-Nov-15 5:34 
AnswerRe: I need to get a count of records, including column Names grouped by UnitName. What am I doing wrong? Pin
Mycroft Holmes13-Nov-15 13:56
professionalMycroft Holmes13-Nov-15 13:56 
AnswerRe: I need to get a count of records, including column Names grouped by UnitName. What am I doing wrong? Pin
RNA Team13-Nov-15 16:32
RNA Team13-Nov-15 16:32 
QuestionSQL Linq, better idea than a join for as enumerable Pin
jkirkerx11-Nov-15 9:09
professionaljkirkerx11-Nov-15 9:09 
AnswerRe: SQL Linq, better idea than a join for as enumerable Pin
Jörgen Andersson11-Nov-15 9:53
professionalJörgen Andersson11-Nov-15 9:53 
GeneralRe: SQL Linq, better idea than a join for as enumerable Pin
jkirkerx12-Nov-15 7:55
professionaljkirkerx12-Nov-15 7:55 
GeneralRe: SQL Linq, better idea than a join for as enumerable Pin
Jörgen Andersson12-Nov-15 9:13
professionalJörgen Andersson12-Nov-15 9:13 
GeneralRe: SQL Linq, better idea than a join for as enumerable Pin
jkirkerx12-Nov-15 10:00
professionaljkirkerx12-Nov-15 10:00 
GeneralRe: SQL Linq, better idea than a join for as enumerable Pin
Jörgen Andersson12-Nov-15 10:06
professionalJörgen Andersson12-Nov-15 10:06 
QuestionFind who dropped a table or column or view Pin
indian1435-Nov-15 7:50
indian1435-Nov-15 7:50 
AnswerRe: Find who dropped a table or column or view Pin
Corporal Agarn5-Nov-15 7:58
professionalCorporal Agarn5-Nov-15 7:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.