Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    2

    Unanswered: DB2 QMF Query question

    Hi. Not sure if this is the place to post this, but I have a question regarding a query I'm trying to write in QMF (using DB2).
    I have 3 tables that I'm joining at once. However, I want to make sure I include ALL records from Table 1. I know how to use a LEFT JOIN when I am joining 2 tables, but it does not work when joining more than 2 tables.
    In the example below, there will be policy numbers on Tpolicies that have NO records on the tpolicy_hist table. In this query below, those records would be dropped. I need to display them - with a null value in the inq_nbr.

    Select a.policy_no, b.birth_date,c.inq_nbr
    from Tpolicies a, tpolicy_addr b, tpolicy_hist c
    where a.policy_no=b.policy_no
    and a.policy_no=c.policy_no
    and b.policy_no=c.policy_no

    Thank you!

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    It is better not to mix traditional join syntax and new join syntax.

    Please try...
    Code:
    SELECT a.policy_no , b.birth_date , c.inq_nbr
     FROM  Tpolicies    a
     INNER JOIN
           tpolicy_addr b
      ON   b.policy_no = a.policy_no
     LEFT  OUTER JOIN
           tpolicy_hist c
      ON   c.policy_no = a.policy_no

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •