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