Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove duplicates the simplest way / explanation
    primarykey
    data
    text
    <p>First I would like to remark that I (as a Newb) did search through several Q &amp; A regarding duplicates in a table though unfortunately for me, I couldn't manipulate the code being used as answer.</p> <p>My table is made out of a report being sorted in SQL Server 2008.</p> <p>I would like to know how do I remove duplicate records and with an explanation.</p> <pre><code>"MyTable": Column1 (PK-auto incremental table's record ID) Column2 (some TXT) Column3 (Some TXT) Column4 (SmallDateTime) Column5 is empty </code></pre> <p>Column5 will hold the value of <code>SUM(count of deleted duplicates including this survived row)</code></p> <p>The key to the solution in may case is if <code>[column2 and column3]</code> have multiple records with same content (hence Duplicates) only they don't always share the same date (<code>column4</code>).</p> <p>From this:</p> <pre><code>col1 col2 col3 col4 col5 ---- ----- ---- ----------- ---- 1 [abc] [4] [10/1/2012] null 2 [abc] [1] [12/1/2012] null 3 [ghi] [6] [4/1/2012] null 4 [def] [5] [8/1/2012] null 5 [abc] [4] [10/1/2012] null 6 [def] [5] [12/1/2012] null 7 [ghi] [6] [15/1/2012] null 8 [abc] [4] [17/1/2012] null 9 [ghi] [6] [6/1/2012] null 10 [abc] [1] [13/1/2012] null </code></pre> <p>Into this:</p> <pre><code>col1 col2 col3 col4 col5 ---- ----- ---- ----------- ---- 8 [abc] [4] [17/1/2012] 2 10 [abc] [1] [13/1/2012] 3 6 [def] [5] [12/1/2012] 2 7 [ghi] [6] [15/1/2012] 3 </code></pre> <p>Meaning leave the latest (1) as a representation of every duplicated record.</p> <p>++ReEditing++</p> <p>Aaron Bertrand shawnt00 e2nburner... and rest of u all i can't say how much i thank your Reply although i did not yet comprehend that mass of code. i am now going to check those codes but not b4 thanking you guys !!</p> <p>when i first started to program and needed sql querys, after using </p> <pre><code>Select * From MyTable </code></pre> <p>... my 1'st SQL Statement ...</p> <p>i said HEY i know SQL !!! .... Now ... look at that deep knowledge of you guys ... THANKS A LOT i know that this post in StackOverFlow will be further useful for other beginners too</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload