home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / database / oracle / 2510 < prev    next >
Encoding:
Internet Message Format  |  1992-12-15  |  1.8 KB

  1. Path: sparky!uunet!munnari.oz.au!manuel.anu.edu.au!sserve!hhcs.gov.au!cbr2!champs
  2. Newsgroups: comp.databases.oracle
  3. Subject: Re: Help with SQL Syntax
  4. Message-ID: <1992Dec15.191831.1@cbr2>
  5. From: champs@cbr2
  6. Date: 15 Dec 92 19:18:31 GMT
  7. References: <1992Dec4.202332.21512@cbfsb.cb.att.com>
  8. Lines: 43
  9.  
  10. In article <1992Dec4.202332.21512@cbfsb.cb.att.com>, gerette@cbnewsb.cb.att.com (marianne.g.pittorino) writes:
  11. > Let's call the first table FIRST and the second table SECOND.  The data in
  12. > I need an SQL statement that will select the rows in FIRST that do not
  13. > match any row in SECOND (and vice versa).  For example, let's pretend we have
  14. > the following data:
  15. >     FIRST            SECOND
  16. >     -----            ------
  17. >     1111            1111
  18. >     2222            2222
  19. >     3333            4444
  20. >     5555            5555
  21. > I need to know that 3333 exists in FIRST but not in SECOND, and that 4444
  22. > exists in SECOND but not in FIRST.  I do not need to know this in the same
  23. > SQL statement.
  24. > Does anyone know how to do this?
  25.  
  26. After consulting the SQL reference manual, the simplest way (I don't know if
  27. it's the most resource efficient way) is as follows:
  28.  
  29.     SELECT COL FROM FIRST
  30.          MINUS
  31.         SELECT COL FROM SECOND;
  32.  
  33. This returns all rows from FIRST that are not is second, so just reverse the
  34. table names to get the appropriate rows from SECOND.
  35.  
  36. Bye for now.
  37. -------------------------------------------------------------------------------
  38.     /\       Steven Champness
  39.    /  \      Dept Health Housing and Community Services
  40.   /    \     Brisbane Queensland
  41.  /      \     via
  42. /   /    \   Canberra Australia
  43. \  / /   /
  44.  \/ / / /    MACINTOSH SOFTWARE AXIOM : If you need a manual to operate it
  45.   \/ / /                                it wasn't designed properly in the
  46.    \/ /                                 first place !
  47.     \/
  48.