I have been researching how to find duplicates of a record in a database and in that I find this answer:
Finding Duplicates in MySQL - This answer aims to find duplicates in multiple columns of the same table, while I look for duplicates in a single column.
But I don't achieve my goal. what I intend is to visualize the N duplicate records.
Structure and example data:
DROP TABLE IF EXISTS `prueba`;
CREATE TABLE IF NOT EXISTS `prueba` (
`id` bigint(21) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Id de la tabla',
`name` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'nombre',
`prod_ft` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'codigo',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT;
SET FOREIGN_KEY_CHECKS=1;
INSERT INTO `prueba` VALUES
(1, 'Pepe Pelotas 1', 'FT202201001'),
(2, 'Pepe Pelotas 2', 'FT202201001'),
(3, 'Pepe Pelotas 3', 'FT202201003'),
(4, 'Pepe Pelotas 4', 'FT202201004'),
(5, 'Pepe Pelotas 5', 'Actualizar');
Query:
SELECT * FROM prueba WHERE `prod_ft` != 'Actualizar' GROUP BY `prod_ft` HAVING COUNT(*) > 1;
Result:
Expected result: