Skip to content

Evitar registros repetidos SQL Server

February 22, 2012

Lo podemos solucionar con el uso del comando COUNT(*):

SELECT col1, count(*)
FROM t1
GROUP BY col1
--  
INSERT INTO t1
(
col1, countCol1)
SELECT col1, count(*)
FROM t1
GROUP BY col1
Para la inserción, vemos que creando un campo donde guardar los contadores 
de cada registro, nos basta. Después los podemos o no mostrar.

From → Consultas SQL

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: