home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / p4w_all.zip / TI1435.ASC < prev    next >
Text File  |  1993-04-14  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1435
  9.   VERSION  :  1.0
  10.        OS  :  WIN
  11.      DATE  :  April 14, 1993                           PAGE  :  1/3
  12.  
  13.     TITLE  :  Doing "Not-in" Queries
  14.  
  15.  
  16.  
  17.  
  18.   Intended Audience
  19.   All Paradox users
  20.  
  21.   Prerequisites
  22.   Familiarity with queries
  23.   Chapters 6 and 7, User's Guide
  24.  
  25.   Purpose of the TI
  26.   This document discusses how to perform a query which will select
  27.   the records from one table that do not exist in another.
  28.  
  29.  
  30.   It is often desirable to select records from one table that do
  31.   not exist in another table.  This type of query is often called a
  32.   "Not-in" query (Which records from one table are "not in"
  33.   another?).  The following example uses two tables "Customer" and
  34.   "Orders" to illustrate how to perform a "Not-in" query.
  35.  
  36.   Suppose that you have two tables, "Customer" and "Orders" as
  37.   follows:
  38.  
  39.   CUSTOMER╦═Cust #═╦══Last Name══╦══First Name══╗
  40.        1  ║  1015  ║  Elkins     ║  Eugene      ║
  41.        2  ║  1020  ║  Fenton     ║  Mark        ║
  42.        3  ║  1055  ║  Harding    ║  Jim         ║
  43.        4  ║  1056  ║  Wilden     ║  Marc        ║
  44.        5  ║  1319  ║  Fenton     ║  Teresa      ║
  45.        6  ║  1341  ║  Goves      ║  Cynthia     ║
  46.        7  ║  1342  ║  Goves      ║  Joseph      ║
  47.        8  ║  1685  ║  Murray     ║  Yvonne      ║
  48.        9  ║  1988  ║  Martinez   ║  Susan       ║
  49.       10  ║  2022  ║  Staebell   ║  Alice       ║
  50.  
  51.   ORDERS═╦═Order #═╦════Date═══╦══Cust #═╦═Part══╦══Price══╗
  52.        1 ║    1    ║   7/9/89  ║  1015   ║  DR   ║  46.20  ║
  53.        2 ║    2    ║   7/9/89  ║  1341   ║  WR   ║   3.96  ║
  54.        3 ║    3    ║  7/28/89  ║  1988   ║  HA   ║  12.04  ║
  55.        4 ║    4    ║   8/3/89  ║  1988   ║  GH   ║  14.52  ║
  56.        5 ║    5    ║   8/4/89  ║  1341   ║  DR   ║  46.20  ║
  57.        6 ║    6    ║  8/14/89  ║  1055   ║  VI   ║  65.93  ║
  58.        7 ║    7    ║  8/15/89  ║  1020   ║  DR   ║  46.20  ║
  59.        8 ║    8    ║  8/16/89  ║  1341   ║  GH   ║  14.52  ║
  60.        9 ║    9    ║  8/18/89  ║  1015   ║  TB   ║  33.66  ║
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1435
  75.   VERSION  :  1.0
  76.        OS  :  WIN
  77.      DATE  :  April 14, 1993                           PAGE  :  2/3
  78.  
  79.     TITLE  :  Doing "Not-in" Queries
  80.  
  81.  
  82.  
  83.  
  84.   The query shown below asks the question "Which customers have
  85.   never placed an order?".  This query links the Customer table and
  86.   the Orders table with an example element (c), and uses the
  87.   inclusion operator (!) in the Cust # field of the Customer table.
  88.   The inclusion operator tells Paradox to include every customer
  89.   number from the Customer table, regardless of whether it exists
  90.   in the Orders table.  The Orders table contains the expression
  91.   "count=0" in the Cust # field.  This tells Paradox to count the
  92.   number of occurrences of each customer number in the Orders
  93.   table, and only include the customer numbers that occur zero
  94.   times.
  95.  
  96.   NOTE: The underscore character "_" represents an example element.
  97.         To create an example element, press [F5] (or type an
  98.         underscore "_")_, then type the characters you want to use.
  99.         The example element will be highlighted.
  100.  
  101.  
  102.   CUSTOMER╦═Cust #═╦══Last Name══╦══First Name══╗
  103.           ║ √ _c!  ║             ║              ║
  104.  
  105.  
  106.   ORDERS═╦═Order #═╦════Date═══╦══Cust #═════╦═Part══╦══Price══╗
  107.          ║         ║           ║ _c, count=0 ║       ║         ║
  108.  
  109.  
  110.   ANSWER═╦═Cust #═╗
  111.        1 ║ 1056   ║
  112.        2 ║ 1319   ║
  113.        3 ║ 1342   ║
  114.        4 ║ 1685   ║
  115.        5 ║ 2022   ║
  116.  
  117.  
  118.   The resulting Answer table shows that customer numbers 1056,
  119.   1319, 1342, 1685, and 2022 have not placed orders.
  120.  
  121.   To help understand how this query works, try changing the
  122.   "count=0" in the Cust # field of the Orders table to "calc count
  123.   all".  When you run the query, the resulting Answer table will
  124.   have 10 records, since there are 10 records in the Customer
  125.   table.  The "Count of Cust #" field will show the number of times
  126.   each customer appears in the Orders table.  The records for
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1435
  141.   VERSION  :  1.0
  142.        OS  :  WIN
  143.      DATE  :  April 14, 1993                           PAGE  :  3/3
  144.  
  145.     TITLE  :  Doing "Not-in" Queries
  146.  
  147.  
  148.  
  149.  
  150.   customer numbers 1056, 1319, 1342, 1685, and 2022 show a count of
  151.   zero.  These same customer numbers appear in the Answer table for
  152.   the "Not-in query".
  153.  
  154.   The information in this document came from Brian J. Smith's
  155.   article "How to Ask 'Not-In' Queries" which first appeared in the
  156.   October 1989 issue of "Instant Scripts", a publication of the
  157.   LAPALS user group in Southern California.
  158.  
  159.  
  160.   Suggested Reading:
  161.   Chapters 6 and 7, User's Guide
  162.  
  163.  
  164.   DISCLAIMER: You have the right to use this technical information
  165.   subject to the terms of the No-Nonsense License Statement that
  166.   you received with the Borland product to which this information
  167.   pertains.
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.