home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / bit / listserv / sasl / 4028 < prev    next >
Encoding:
Text File  |  1992-09-03  |  4.7 KB  |  123 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!uvaarpa!darwin.sura.net!paladin.american.edu!auvm!LEICESTER.AC.UK!MAIL_SYSTEM
  3. Via: uk.ac.leicester; Thu, 3 Sep 1992 15:58:27 +0100
  4. Message-ID: <SAS-L%92090311032958@VTVM2.BITNET>
  5. Newsgroups: bit.listserv.sas-l
  6. Date:         Thu, 3 Sep 1992 15:58:00 BST
  7. Reply-To:     Mail_System@LEICESTER.AC.UK
  8. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  9. From:         Mail_System@LEICESTER.AC.UK
  10. Subject:      %% Undelivered Mail %%
  11. Comments: To: SAS-L <SAS-L@VTVM2.CC.VT.EDU>
  12. Lines: 109
  13.  
  14. Your mail was not delivered as follows:
  15. %MAIL-E-USERSPEC, invalid user specification '@UK.AC.LEICESTER.IRIX'
  16.  
  17. Your original mail header and message follow.
  18.  
  19. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  20. Via: UK.AC.NSFNET-RELAY; Thu, 3 Sep 92  15:57 BST
  21. Received: from vtvm2.cc.vt.edu by sun3.nsfnet-relay.ac.uk with Internet SMTP
  22.           id <sg.24811-0@sun3.nsfnet-relay.ac.uk>;
  23.           Thu, 3 Sep 1992 15:57:11 +0100
  24. Received: from vtvm2.cc.vt.edu by VTVM2.CC.VT.EDU (IBM VM SMTP V2R2) with BSMTP
  25.           id 9451; Thu, 03 Sep 92 10:56:11 EDT
  26. Received: from VTVM2.BITNET by vtvm2.cc.vt.edu (Mailer R2.08 R208002)
  27.           with BSMTP id 0631; Thu, 03 Sep 92 10:56:09 EDT
  28. Date: Thu, 3 Sep 1992 10:48:34 EDT
  29. Reply-To: Andy Norton <76350.1604@COM.COMPUSERVE>
  30. Original-Sender: "SAS(r) Discussion" <SAS-L@EDU.VT.CC.VTVM2>
  31. From: Andy Norton <76350.1604@COM.COMPUSERVE>
  32. Subject: Re: Finding non-dups via SQL (multiple keys)
  33. Comments: To: SAS-L <SAS-L@AWIIMC12.IMC.UNIVIE.AC.AT>
  34. To: Multiple recipients of list SAS-L <SAS-L@EDU.VT.CC.VTVM2>
  35. Sender: SAS-L@EDU.VT.CC.VTVM2
  36.  
  37. ----------------------------------------------------------------------
  38. CONTENT:    Information
  39. SUMMARY:   Jim Clark's response to Ray Pass is correct for single
  40.            keys.  Here are solutions for multiple keys.
  41. REL/PLTF:  6.07.01/CMS, 6.04/PC-DOS
  42. E-ADDR:    76350.1604@compuserve.com
  43. NAME:      Andy Norton
  44. ADDRESS:   Trilogy Consulting, 5228 Lovers Lane, Kalamazoo MI 49002
  45. PHONE:     (616) 344-2191
  46. ----------------------------------------------------------------------
  47.  
  48. Ray Pass had asked for a method to identify CASENO's in FILE1 that do
  49. not occur in FILE2.
  50.  
  51. Jim Clark responded with
  52. > title 'Eval Courses NOT IN Class Courses';
  53. > select distinct e.ident, e.ins
  54. >    from work.check e, f.course c
  55. >    where e.ident not in
  56. >     (select c.ident
  57. >      from f.course c)
  58. >    order by e.ident;
  59.  
  60. The general approach is correct and sufficient for Ray's problem.  I
  61. think you could use simply
  62.   select    CHECK.*
  63.   from      WORK.CHECK
  64.   where     CHECK.IDENT not in
  65.             ( select IDENT
  66.               from   F.COURSE)
  67.   order by  IDENT;
  68. to get the same result.  In other words, it is not necessary to join E
  69. with C in order to reference table C in a subquery.
  70.  
  71. The main purpose of my posting, however, is to point out that this
  72. method falls apart when you need to match on two keys instead of one.
  73. Suppose the IDENT's are repeated within different colleges, and you
  74. need to do a combined analysis.  Now the observations are identified
  75. with {COLLEGE, IDENT}.  The IN operator only works for a single
  76. variable, so can't handle this situation.
  77.  
  78. This is a widespread weakness in the design of SQL:  programs that work
  79. with single columns often cannot be extended to handle multiple
  80. columns.  If you write the program to handle multiple keys, it will be
  81. able to handle the single-key situation.
  82.  
  83. For a general solution which works with multiple keys, use
  84.   select    *
  85.   from      WORK.CHECK
  86.   where     not exists
  87.             ( select *
  88.               from   F.COURSE
  89.               where  COLLEGE = CHECK.COLLEGE and
  90.                      IDENT   = CHECK.IDENT)
  91.   order by  COLLEGE, IDENT;
  92.  
  93.   This is fairly intelligible but can be inefficient with the current
  94. optimizer, because the subquery is independently evaluated for each set
  95. of {COLLEGE, IDENT} values.  Defining indexes on COLLEGE and IDENT (in
  96. the COURSE file) could help.
  97.  
  98. It may be possible for the optimizer to automatically convert
  99. subqueries to joins in the future.
  100.  
  101. This alternative may be more efficient (depending on factors such as
  102. how many distinct {COLLEGE, IDENT} sets there are).  I haven't tested
  103. enough to determine exactly what the trade-offs are:
  104.  
  105.   select    CHECK.*
  106.   from      WORK.CHECK,
  107.             ( select COLLEGE, IDENT
  108.               from   WORK.CHECK
  109.               except
  110.               select COLLEGE, IDENT
  111.               from   F.COURSE) as NONDUP
  112.   where     CHECK.COLLEGE = NONDUP.COLLEGE and
  113.             CHECK.IDENT   = NONDUP.IDENT
  114.   order by  COLLEGE, IDENT;
  115.  
  116. Unlike the earlier subquery solution, this program processes all of the
  117. different {COLLEGE, IDENT} pairs together.
  118.  
  119.                     Andy
  120.  
  121. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  122. End of returned mail
  123.