home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / database / 6318 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  2.7 KB

  1. Xref: sparky comp.databases:6318 comp.databases.theory:388 comp.databases.oracle:1373
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!ogicse!sequent!muncher.sequent.com!map
  3. From: map@sequent.com (Michael Perry)
  4. Newsgroups: comp.databases,comp.databases.theory,comp.databases.oracle
  5. Subject: Re: Is this a bug or a limitation of the SQL language
  6. Message-ID: <1992Aug25.205811.13135@sequent.com>
  7. Date: 25 Aug 92 20:58:11 GMT
  8. Article-I.D.: sequent.1992Aug25.205811.13135
  9. References: <1992Aug23.074048.16681@prism.poly.edu> <1992Aug24.100941.24827@dk.oracle.com> <JOEY.92Aug24091348@elysium.berkeley.edu>
  10. Sender: usenet@sequent.com (usenet )
  11. Organization: Sequent Computer Systems Inc.
  12. Lines: 53
  13. Nntp-Posting-Host: sequent.sequent.com
  14.  
  15. In article <JOEY.92Aug24091348@elysium.berkeley.edu> joey@berkeley.edu (Joe Hellerstein) writes:
  16. >In article <1992Aug24.100941.24827@dk.oracle.com> bengsig@dk.oracle.com (Bjorn Engsig) writes:
  17. >
  18. >>   Article <1992Aug23.074048.16681@prism.poly.edu> by sjha@prism.poly.edu
  19. >>   (Salil Kumar Jha) asks why this is illegal SQL:
  20. >>   |
  21. >>   |select * from emp 
  22. >>   |where salary between
  23. >>   |(select salary from emp where ename = 'Larry')
  24. >>   |and
  25. >>   |(select salary from emp where ename = 'John')
  26. >>   |
  27. >>   The problem is that SQL is a poorly defined laguage.  Read Date's
  28. >>   "Critique Of The SQL Language".  There are numerous examples like yours.
  29. >>   -- 
  30. >>   Bjorn Engsig,        Internet: bengsig@oracle.com
  31. >>   ORACLE Corporation.    BANG-net: uunet!oracle!bengsig
  32. >>               Private : bjorn@login.dkuug.dk.
  33. >
  34. >Well *that's* not too helpful!  No, SQL isn't great.  But there's a
  35. >better way of expressing the query, which is what the original poster
  36. >was after.
  37. >
  38. >You want to avoid subqueries whenever possible.  To get what you need,
  39. >try the following:
  40. >
  41. >select distinct e1.* 
  42. >  from emp e1, emp laremp, emp johnemp
  43. > where laremp.ename = 'Larry'
  44. >   and johnemp.ename = 'John'
  45. >   and e1.salary between laremp.salary and johnemp.salary;
  46. >
  47. >(That's assuming I've got the "between" syntax right, which I'm not
  48. >sure about.)
  49. >
  50. >This version of the query uses joins instead of subqueries, allowing
  51. >for more join orders and join methods.  The added Distinct is just
  52. >there to avoid having lots of dups in the output.  This might run
  53. >marginally slower than your query (because of the sort for distinct),
  54. >but is quite likely to run a whole lot faster (due to more join
  55. >options for the optimizer.)
  56. >
  57. >If you want technical discussion of this issue, see
  58. >"Extensible/Rule-Based Query Rewrite Optimization in Starburst" in
  59. >SIGMOD '92.
  60. >
  61. >Joe Hellerstein
  62.  
  63. Actually, the reason the query won't work is that the sub-queries
  64. can return MULTIPLE values [employees named Larry] and the main
  65. query has to have ONE value for each end of the between.
  66.  
  67. Mike
  68.