home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / sql / subquery.shr < prev    next >
Text File  |  1988-02-08  |  2KB  |  60 lines

  1.          
  2.          
  3.          
  4.          
  5.          SUBQUERIES (SHORT VERSION)
  6.  
  7.          Often, we need to break down our query into more than one 
  8.          query.  Each query will have its own select.  We need 
  9.          subqueries when, in analyzing a query, we find that we need 
  10.          information from one query before we can process another query.  
  11.          In some cases we can either join tables or use a subquery.  
  12.          Typically, subqueries retrieve information more rapidly than 
  13.          joining tables.
  14.  
  15.          Subqueries work "backwards" in that the last select statement is 
  16.          executed first and so on.
  17.  
  18.          Assume you have the following query:  Which customers have 
  19.          purchased products from salespersons who work under manager 
  20.          number 20? One approach would be to find all the salespeople 
  21.          that have the same number as one of the group of employees in 
  22.          the employee table who have a 20 in the mgrn column. 
  23.          
  24.          select distinct cc 
  25.          from s 
  26.          where sn in 
  27.          (select enum 
  28.           from e 
  29.           where mgrn = 20);
  30.                                                                                 
  31.          cc 
  32.          -- 
  33.          c2 
  34.             
  35.          1 row selected
  36.  
  37.          Subqueries can be used in a variety of ways to extract data that 
  38.          would otherwise be unavailable.  Become a registered user and 
  39.          find out all the details.
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.                                       SUBQ-1
  59.          
  60.