UNION in an SQL-SELECT Produces Only Distinct Records

Last reviewed: April 17, 1995
Article ID: Q102892
The information in this article applies to:
  • Microsoft FoxPro for MS-DOS, versions 2.0 and 2.5

SUMMARY

When you are using the UNION clause to combine the results of two SELECT statements, the FoxPro implementation of SQL will eliminate any duplicate rows.

If you want duplicate rows to appear in the resulting output, include the ALL keyword after the UNION clause.

MORE INFORMATION

The online Help and "Language Reference" manual state the following:

   Include the UNION clause to combine the final results of one
   SELECT with the final results of another SELECT. By default,
   UNION checks the combined results and eliminates duplicate rows.
   Use the optional ALL key word to prevent UNION from eliminating
   duplicate rows from the combined results.

   For example, given table A and B, each of which may contain
   duplicate records which are to be preserved and combined into a
   single cursor, issue the following command:

      SELECT * from A ;
         UNION ALL ;
      SELECT * from B

   A and B must contain the same number of columns, and the
   corresponding columns must be of the same type.


Additional reference words: FoxDos 2.00 2.50
KBCategory: kbprg
KBSubcategory:


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 17, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.