Checking duplicate MySQL records

2

I have a database, where the company's invoices are stored, and I need to see the duplicate records (invoices that have the same series, number and type). For each record I have an id id that identifies them. What I want to list are all the ones that are duplicated, not the quantity. Searching the web I have not found any sentence with which I can resolve this.

For example, of those listed below, I want to see only those that are duplicated (A 809 and A 810):

**Tipo Serie Nro  Estado          Id**

111  A     807  Aceptada        9065
111  A     808  ErrorValidacion 7509
111  A     809  Aceptada        7519
111  A     809  ErrorValidacion 8287
111  A     809  ErrorValidacion 9066
111  A     809  ErrorValidacion 9123
111  A     810  ErrorValidacion 8288
111  A     810  ErrorValidacion 9067
111  A     810  ErrorValidacion 7574
111  A     810  Aceptada        7577
111  A     810  ErrorValidacion 9124

Thank you.

    
asked by jam1981 07.07.2016 в 23:22
source

3 answers

4

The answer is this (I've tried it):

    SELECT tipo,serie,nro
    FROM tabla
    WHERE nro
    IN (
    SELECT nro
    FROM tabla
    GROUP BY tipo,serie,nro
    HAVING count( nro ) >1
    )
    ORDER BY nro,tipo,serie
    
answered by 08.07.2016 / 15:56
source
3

Try this query

SELECT COUNT(0),Nro,Serie,Tipo from kk group by Nro,Serie,Tipo having count(0)>1
    
answered by 08.07.2016 в 00:16
0

You can make a query including " HAVING count (*) > 1 "to show only duplicates, the" GROUP_CONCAT (id) "allows you to group separated by", "the id's that are repeated (be careful as it has a character limit but it can be configured), with the GROUP_BY (series) define what you want to find that is duplicated.

SELECT group_concat(id), serie COUNT(*) Total
FROM invoices
GROUP BY serie
HAVING COUNT(*) > 1;
  

To increase the limit you can try the following:   SET GLOBAL group_concat_max_len = 1000000;

    
answered by 22.06.2018 в 20:10