How to List Duplicate Records in a Field

Last reviewed: April 30, 1996
Article ID: Q115617
The information in this article applies to:
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c

This article describes how to generate a list of duplicate records in a database.

The following code uses a query to generate the list of duplicates and then stores it in a cursor named LISTING:

   USE c:\foxprow\tutorial\invoices
   SELECT invoices.cno, COUNT(invoices.cno) FROM invoices ;
    GROUP BY invoices.cno ;
    HAVING COUNT(invoices.cno)>1 ;
    INTO CURSOR listing

There will be two fields in the cursor LISTING, the first being customer numbers that have duplicates, and the second being the number of duplicates for that customer number.


Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50
2.50a 2.50b 2.60
2.50c
identical same
repeated table
KBCategory: kbprg
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.