{"id":500,"date":"2017-11-10T23:03:17","date_gmt":"2017-11-11T02:03:17","guid":{"rendered":"https:\/\/maurobernal.com.ar\/blog\/?p=500"},"modified":"2017-11-10T23:22:31","modified_gmt":"2017-11-11T02:22:31","slug":"eliminar-repetidos-tsql","status":"publish","type":"post","link":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/","title":{"rendered":"Eliminar Repetidos con TSQL"},"content":{"rendered":"<h2>Eliminar Repetidos con TSQL y la funci\u00f3n Row_Number()<\/h2>\n<p>Hoy vamos usar row_number(), una subconsulta, comando IN para buscar y eliminar registros repetidos.<\/p>\n<p>En esta nueva etapa me he propuesto compartir cada uno de los scripts que siempre son de utilidad cuando se trabaja con bases de datos.<\/p>\n<p>Como siempre son con TSQL para MS SQL Server.<\/p>\n<p>Esta vez veremos <strong>como eliminar registros repetidos de una tabla<\/strong>, solo dejando 1 registro.<\/p>\n<p>El secreto est\u00e1 en el uso del comando <strong>ROW_NUMBER<\/strong><\/p>\n<p>https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/functions\/row-number-transact-sql<\/p>\n<p>&nbsp;<\/p>\n<h3>Cargaremos una tabla de ejemplo MYTABLA<\/h3>\n<pre title=\"Cargando tabla de Ejemplo\" class=\"height-set:true height-mode:2 height:300 lang:tsql decode:true\">IF EXISTS(SELECT 1 FROM sys.tables WHERE object_id = OBJECT_ID('myTable'))\r\nBEGIN;\r\n    DROP TABLE [myTable];\r\nEND;\r\nGO\r\n\r\nCREATE TABLE [myTable] (\r\n    [myTableID] INTEGER NOT NULL IDENTITY(1, 1),\r\n    [Documento] VARCHAR(13) NULL,\r\n    [Nombre] VARCHAR(255) NULL,\r\n    PRIMARY KEY ([myTableID])\r\n);\r\nGO\r\n\r\n\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1695071197799','Jin');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630121141299','Harlan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1637061077799','Armand');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1653081722499','Chadwick');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1695020909099','Fletcher');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1614102485499','Garth');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1624071487999','Cedric');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1678010341799','Prescott');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1695071197799','Jin');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630121141299','Harlan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1637061077799','Armand');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1653081722499','Chadwick');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1691081716399','Harding');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1641101376799','Jakeem');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630020717199','Carlos');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1627101503999','Edan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1636051993199','Samson');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1627041338699','Wylie');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1661032884599','Brennan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1625120186899','Brett');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1642100764499','Ira');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1624052909599','Kyle');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1656062403199','Jordan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1656041722899','Keane');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630122181399','Cain');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1634062813199','Stone');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1615111655399','Elton');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1609092165099','Theodore');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1682111461299','Noble');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1656041722899','Keane');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630122181399','Cain');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1634062813199','Stone');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1615111655399','Elton');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1609092165099','Theodore');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1682111461299','Noble');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1656041722899','Keane');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630122181399','Cain');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1634062813199','Stone');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1615111655399','Elton');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1609092165099','Theodore');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1682111461299','Noble');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1656020101399','Alden');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1657080142799','Tanek');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1678122145299','Fulton');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1684010635799','Reese');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1613011065899','Grant');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630012756499','Jakeem');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1618071462499','Flynn');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1615052518299','Benjamin');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1691052832399','Wylie');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1669013054199','Tucker');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1612110409199','Laith');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1614110752199','Tad');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1699041337299','Chaney');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1650112954899','Jeremy');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1647052552299','Adam');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1643041374799','Denton');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1642081947099','Knox');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1643020793199','Vance');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1632020546699','Thaddeus');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1670032188999','Keegan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1615102660699','Clark');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1693053059399','Hedley');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1661082842999','Beau');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1636081862699','August');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1608070833799','Oscar');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1687121074299','Leo');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1655122056599','Griffith');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1614010191199','Andrew');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1668121357799','Abdul');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1691081716399','Harding');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1641101376799','Jakeem');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630020717199','Carlos');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1627101503999','Edan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1636051993199','Samson');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1627041338699','Wylie');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1661032884599','Brennan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1625120186899','Brett');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1642100764499','Ira');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1602091000299','Jordan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1602060613699','Guy');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1656041722899','Keane');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1630122181399','Cain');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1634062813199','Stone');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1615111655399','Elton');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1609092165099','Theodore');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1682111461299','Noble');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1649101947099','Bradley');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1692080607499','Basil');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1645013071199','Bruce');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1677121204299','Chancellor');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1668110667099','Price');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1644072576599','Driscoll');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1616101911399','August');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1680021349199','Wallace');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1652052495999','Emery');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1692050724999','Talon');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1614111114799','Avram');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1670010342799','Hiram');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1636022785999','Brody');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1609033047099','Stuart');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1669122235799','Moses');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1626080826599','Leo');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1670010510999','Micah');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1676043021599','Jonah');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1621032365499','Len');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1658020481699','Amir');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1611032912899','Len');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1638071718599','Ray');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1676120168199','Kenyon');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1688050847099','Sawyer');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1692051561099','Malcolm');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1664101012499','Nolan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1682121754399','Lucius');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1633112425699','Alvin');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1606040846399','Ralph');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1610061348699','Jin');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1649120964999','Malachi');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1609121778799','Kermit');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1649111157999','Wade');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1625051934199','Simon');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1698060420799','Donovan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1607101359699','Isaiah');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1648100677099','Avram');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1668081567999','Grant');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1613042285999','Keefe');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1626042455399','Joshua');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1676081014999','Amir');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1643042339599','Conan');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1695051340499','Jin');\r\nINSERT INTO myTable([Documento],[Nombre]) VALUES('1610012015699','Akeem');<\/pre>\n<p>&nbsp;<\/p>\n<p>Esta peque\u00f1a tabla de ejemplo tiene la siguiente estructura:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-501\" src=\"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1-248x300.png?resize=248%2C300&#038;ssl=1\" alt=\"eliminar repetidos con tsql\" width=\"248\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1.png?resize=248%2C300&amp;ssl=1 248w, https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1.png?w=269&amp;ssl=1 269w\" sizes=\"auto, (max-width: 248px) 100vw, 248px\" \/><\/p>\n<h3>Buscando repetidos<\/h3>\n<p>Lo primero que haremos es buscar los que tienen el campo <strong>DOCUMENTO<\/strong> repetido usando la funci\u00f3n <strong>Row_Number().\u00a0<\/strong>Esta nos devolver\u00e1 un nuevo campo que llamaremos ORDEN, e indicara las veces que se repite un campo<\/p>\n<pre title=\"Usando Row_Number\" class=\"lang:tsql decode:true\">select *,ROW_NUMBER() over ( PARTITION BY Documento ORDER BY myTableID) as Orden \r\nfrom mytable<\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-502\" src=\"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo2-300x295.png?resize=300%2C295&#038;ssl=1\" alt=\"eliminar repetidos con tsql y row_number()\" width=\"300\" height=\"295\" srcset=\"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo2.png?resize=300%2C295&amp;ssl=1 300w, https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo2.png?resize=36%2C36&amp;ssl=1 36w, https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo2.png?w=316&amp;ssl=1 316w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><em>PARTITION BY Documento\u00a0<\/em>le indicamos que la partici\u00f3n sea el campo documento<\/p>\n<p><em>ORDER BY\u00a0<\/em><em>myTableID\u00a0<\/em>le indicamos el criterio para enumerar. Es decir en orden ascendente por ID del campo. Si tuvi\u00e9semos un campo de tipo fecha (Datetime) podr\u00edamos ordenar por mas nuevo, o viceversa<\/p>\n<p>&nbsp;<\/p>\n<h3>Buscando los repetidos<\/h3>\n<p>Lo primero que haremos es buscar los repetidos usando una subconsulta<\/p>\n<pre title=\"Seleccionando los ID de los repetidos\" class=\"lang:tsql decode:true \">Select myTableID from\r\n(select *,ROW_NUMBER() over ( PARTITION BY Documento ORDER BY myTableID) as Orden \r\nfrom mytable) SubConsulta1\r\nwhere Orden&gt;1<\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-503\" src=\"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo3.png?resize=109%2C274&#038;ssl=1\" alt=\"Eliminiar repetidos TSQL 31 repetidos\" width=\"109\" height=\"274\" \/>Esta consulta devuelve los ID de los repetidos: 31 registros para ser mas especificos<\/p>\n<h3>Eliminado los repetidos<\/h3>\n<p>Ahora los eliminamos usando el comando <strong>IN<\/strong><\/p>\n<pre title=\"Eliminando usando el comando IN\" class=\"lang:tsql decode:true \">begin transaction eliminacion1\r\ndelete from mytable where \r\nmytableID in \r\n(\r\n\r\nSelect myTableID from\r\n(select *,ROW_NUMBER() over ( PARTITION BY Documento ORDER BY myTableID) as Orden \r\nfrom mytable) SubConsulta1\r\nwhere Orden&gt;1\r\n)\r\n\r\ncommit transaction eliminacion1<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Espero que les haya sido \u00fatil.<\/p>\n<p>&nbsp;<\/p>\n<p>El comando <strong>Row_Number()<\/strong> permite trabajar con los registros de forma masiva pudiendo identificar la N aparici\u00f3n.<\/p>\n<p>Mas adelante veremos como eliminar \/ actualizar:<\/p>\n<p>-El \u00faltimo registro de una serie de registros<\/p>\n<p>-El primero, etc&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Eliminar Repetidos con TSQL y la funci\u00f3n Row_Number() Hoy vamos usar row_number(), una subconsulta, comando IN para buscar y eliminar registros repetidos. En esta nueva etapa me he propuesto compartir&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,3],"tags":[131,8,133,130,132,29],"class_list":["post-500","post","type-post","status-publish","format-standard","hentry","category-blog","category-t-sql","tag-in","tag-mssql-2","tag-repetidos","tag-row_number","tag-subconsulta","tag-tsql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Eliminar repetidos con TSQL en MSQL Server y Row_Number<\/title>\n<meta name=\"description\" content=\"Buscar y Eliminar repetidos con TSQL en MS SQL Server a trav\u00e9s de la funci\u00f3n Row_Number(), una subconsulta y el comando IN\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Eliminar repetidos con TSQL en MSQL Server y Row_Number\" \/>\n<meta property=\"og:description\" content=\"Buscar y Eliminar repetidos con TSQL en MS SQL Server a trav\u00e9s de la funci\u00f3n Row_Number(), una subconsulta y el comando IN\" \/>\n<meta property=\"og:url\" content=\"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/\" \/>\n<meta property=\"og:site_name\" content=\"devops Mauro Bernal\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-11T02:03:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-11-11T02:22:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1-248x300.png\" \/>\n<meta name=\"author\" content=\"Mauro Bernal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@_maurobernal\" \/>\n<meta name=\"twitter:site\" content=\"@_maurobernal\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mauro Bernal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/\"},\"author\":{\"name\":\"Mauro Bernal\",\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/#\\\/schema\\\/person\\\/09c4dbdfb59b20e015c703fd19713283\"},\"headline\":\"Eliminar Repetidos con TSQL\",\"datePublished\":\"2017-11-11T02:03:17+00:00\",\"dateModified\":\"2017-11-11T02:22:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/\"},\"wordCount\":287,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/#\\\/schema\\\/person\\\/09c4dbdfb59b20e015c703fd19713283\"},\"image\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/eliminar_repetidos_ejemplo1-248x300.png\",\"keywords\":[\"in\",\"mssql\",\"repetidos\",\"row_number\",\"subconsulta\",\"tsql\"],\"articleSection\":[\"Blog\",\"T-SQL\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/\",\"url\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/\",\"name\":\"Eliminar repetidos con TSQL en MSQL Server y Row_Number\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/eliminar_repetidos_ejemplo1-248x300.png\",\"datePublished\":\"2017-11-11T02:03:17+00:00\",\"dateModified\":\"2017-11-11T02:22:31+00:00\",\"description\":\"Buscar y Eliminar repetidos con TSQL en MS SQL Server a trav\u00e9s de la funci\u00f3n Row_Number(), una subconsulta y el comando IN\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/eliminar_repetidos_ejemplo1.png?fit=269%2C325&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/eliminar_repetidos_ejemplo1.png?fit=269%2C325&ssl=1\",\"width\":269,\"height\":325,\"caption\":\"eliminar repetidos con tsql\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/eliminar-repetidos-tsql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Eliminar Repetidos con TSQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/\",\"name\":\"devops Mauro Bernal\",\"description\":\"Cuando tu trabajo es hacer que las cosas funcionen bien...\",\"publisher\":{\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/#\\\/schema\\\/person\\\/09c4dbdfb59b20e015c703fd19713283\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/maurobernal.com.ar\\\/blog\\\/#\\\/schema\\\/person\\\/09c4dbdfb59b20e015c703fd19713283\",\"name\":\"Mauro Bernal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-maurobernal.png?fit=1740%2C1740&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-maurobernal.png?fit=1740%2C1740&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-maurobernal.png?fit=1740%2C1740&ssl=1\",\"width\":1740,\"height\":1740,\"caption\":\"Mauro Bernal\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/maurobernal.com.ar\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-maurobernal.png?fit=1740%2C1740&ssl=1\"},\"description\":\"Desarrollo de Sistemas en .Net, IT Callcenters, DBA de SQL Server, Mikrotik, Pentest y T\u00e9cnico consultor de Sistemas Bejerman\",\"sameAs\":[\"https:\\\/\\\/maurobernal.com.ar\",\"https:\\\/\\\/x.com\\\/_maurobernal\",\"https:\\\/\\\/youtube.com\\\/maurobernal\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Eliminar repetidos con TSQL en MSQL Server y Row_Number","description":"Buscar y Eliminar repetidos con TSQL en MS SQL Server a trav\u00e9s de la funci\u00f3n Row_Number(), una subconsulta y el comando IN","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/","og_locale":"es_ES","og_type":"article","og_title":"Eliminar repetidos con TSQL en MSQL Server y Row_Number","og_description":"Buscar y Eliminar repetidos con TSQL en MS SQL Server a trav\u00e9s de la funci\u00f3n Row_Number(), una subconsulta y el comando IN","og_url":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/","og_site_name":"devops Mauro Bernal","article_published_time":"2017-11-11T02:03:17+00:00","article_modified_time":"2017-11-11T02:22:31+00:00","og_image":[{"url":"https:\/\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1-248x300.png","type":"","width":"","height":""}],"author":"Mauro Bernal","twitter_card":"summary_large_image","twitter_creator":"@_maurobernal","twitter_site":"@_maurobernal","twitter_misc":{"Escrito por":"Mauro Bernal","Tiempo de lectura":"8 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#article","isPartOf":{"@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/"},"author":{"name":"Mauro Bernal","@id":"https:\/\/maurobernal.com.ar\/blog\/#\/schema\/person\/09c4dbdfb59b20e015c703fd19713283"},"headline":"Eliminar Repetidos con TSQL","datePublished":"2017-11-11T02:03:17+00:00","dateModified":"2017-11-11T02:22:31+00:00","mainEntityOfPage":{"@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/"},"wordCount":287,"commentCount":0,"publisher":{"@id":"https:\/\/maurobernal.com.ar\/blog\/#\/schema\/person\/09c4dbdfb59b20e015c703fd19713283"},"image":{"@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#primaryimage"},"thumbnailUrl":"https:\/\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1-248x300.png","keywords":["in","mssql","repetidos","row_number","subconsulta","tsql"],"articleSection":["Blog","T-SQL"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/","url":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/","name":"Eliminar repetidos con TSQL en MSQL Server y Row_Number","isPartOf":{"@id":"https:\/\/maurobernal.com.ar\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#primaryimage"},"image":{"@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#primaryimage"},"thumbnailUrl":"https:\/\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1-248x300.png","datePublished":"2017-11-11T02:03:17+00:00","dateModified":"2017-11-11T02:22:31+00:00","description":"Buscar y Eliminar repetidos con TSQL en MS SQL Server a trav\u00e9s de la funci\u00f3n Row_Number(), una subconsulta y el comando IN","breadcrumb":{"@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#primaryimage","url":"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1.png?fit=269%2C325&ssl=1","contentUrl":"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2017\/11\/eliminar_repetidos_ejemplo1.png?fit=269%2C325&ssl=1","width":269,"height":325,"caption":"eliminar repetidos con tsql"},{"@type":"BreadcrumbList","@id":"https:\/\/maurobernal.com.ar\/blog\/eliminar-repetidos-tsql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/maurobernal.com.ar\/blog\/"},{"@type":"ListItem","position":2,"name":"Eliminar Repetidos con TSQL"}]},{"@type":"WebSite","@id":"https:\/\/maurobernal.com.ar\/blog\/#website","url":"https:\/\/maurobernal.com.ar\/blog\/","name":"devops Mauro Bernal","description":"Cuando tu trabajo es hacer que las cosas funcionen bien...","publisher":{"@id":"https:\/\/maurobernal.com.ar\/blog\/#\/schema\/person\/09c4dbdfb59b20e015c703fd19713283"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/maurobernal.com.ar\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":["Person","Organization"],"@id":"https:\/\/maurobernal.com.ar\/blog\/#\/schema\/person\/09c4dbdfb59b20e015c703fd19713283","name":"Mauro Bernal","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2023\/07\/logo-maurobernal.png?fit=1740%2C1740&ssl=1","url":"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2023\/07\/logo-maurobernal.png?fit=1740%2C1740&ssl=1","contentUrl":"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2023\/07\/logo-maurobernal.png?fit=1740%2C1740&ssl=1","width":1740,"height":1740,"caption":"Mauro Bernal"},"logo":{"@id":"https:\/\/i0.wp.com\/maurobernal.com.ar\/blog\/wp-content\/uploads\/2023\/07\/logo-maurobernal.png?fit=1740%2C1740&ssl=1"},"description":"Desarrollo de Sistemas en .Net, IT Callcenters, DBA de SQL Server, Mikrotik, Pentest y T\u00e9cnico consultor de Sistemas Bejerman","sameAs":["https:\/\/maurobernal.com.ar","https:\/\/x.com\/_maurobernal","https:\/\/youtube.com\/maurobernal"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/posts\/500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/comments?post=500"}],"version-history":[{"count":1,"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/posts\/500\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/posts\/500\/revisions\/504"}],"wp:attachment":[{"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/media?parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/categories?post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/maurobernal.com.ar\/blog\/wp-json\/wp\/v2\/tags?post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}