[Skip Global Navigation]

Training

Training Home

SPSS Trainer Tip: ShowCase® Query™ and Report Writer™

Instructor profile

Name: Jane Black Eagle

About Jane: Jane, a senior solutions consultant, has worked for SPSS since 1997. She has successfully helped numerous SPSS customers solve their business problems through successful implementation of SPSS products. Jane holds both a BA in business administration and a BS in information systems.

Combining information from two detail files in one

Do you often encounter the many-to-many join situation when writing a query or report that needs to combine information from two detail files in one result set? This situation is a common one, particularly for JD Edwards (now Oracle) users who are looking for sales information from both the F4211 and the F42119. One way to avoid many-to-many joins is to use a union. A union enables you to write two select statements, each targeting a necessary detail file, and then combine the results into a single set.

There are four requirements for creating joins:

To create a union:

The following example is a union bringing together current sales from SCSAMPLE65.ORDERS and historical sales from SCDB1.ORDMAST:

  SELECT
     CUSTOMERS.CUST_ID,
     CUSTNAME,
     SUM( EXTPRICE ) AS "SumExtprice"
  FROM
     SCSAMPLE65.CUSTOMERS CUSTOMERS,
     SCSAMPLE65.ORDERS ORDERS
  WHERE
     CUSTOMERS.CUST_ID = ORDERS.CUST_ID
  GROUP BY
     CUSTOMERS.CUST_ID,
     CUSTNAME

  UNION SELECT
     CSTHDR.CUSTID AS CUST_ID,
     CONAME AS CUSTNAME,
     SUM( TOTBIL ) AS "SumExtprice"
  FROM
     SCDB1.CSTHDR CSTHDR,
     SCDB1.INVHDR INVHDR
  WHERE
     CSTHDR.CUSTID = INVHDR.CUSTID

  GROUP BY
     CSTHDR.CUSTID,
     CONAME
  ORDER BY
     1

We offer SPSS courses at locations around the world.
Find a course in the location nearest to you.