joining multiple tables based on 1 criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cyprus106
    New Member
    • Apr 2008
    • 31

    joining multiple tables based on 1 criteria

    Apparently, Im incapable of properly executing this query! I've been at this for far too long and gotten nowhere. Forgive me if this is a umb mistake; I'm not great at SQL.

    I've got three tables, MASTER, RETAIL, and AUDIT... MASTER and RETAIL have the same fields, except each record has a unique ITEMNO, and master's numbers are positive and retail's are negative. AUDIT contains some of both table's item numbers in it. I just want to join audit to both tables based on the ITEMNO, (Audit's ITEMNO field is actually called MMNO, if that matters) I can JOIN one or the other and it'll show up with the right fields, but when I try to join both it returns with no records. I know I'm messing up, I just don't know how to fix it.

    This is what I've got (take out either master OR retail and it works fine):
    SELECT AUDIT.TRANSACTI ONNO,AUDIT.DATI M, AUDIT.MMNO, AUDIT.COPYS, AUDIT.PRICE,
    MASTER.ITEMNO, MASTER.MTITLE, MASTER.MSRP,
    RETAIL.ITEMNO, RETAIL.MTITLE, RETAIL.MSRP,
    FROM BUYBACKAUDIT
    JOIN RETAIL ON AUDIT.ITEMNO=RE TAIL.MMBSNO
    JOIN MASTER ON AUDIT.ITEMNO=MA STER.MMBSNO

    Any help would be much appreciated. Thanks!
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What's in AUDIT? Positive or Negative? or both?

    -- CK

    Comment

    • Cyprus106
      New Member
      • Apr 2008
      • 31

      #3
      both. So I want to see what item numbers are in AUDIT and match them to the master and retail records accordingly.

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Use left join on both, instead of inner join

        -- CK

        Comment

        • snathanm
          New Member
          • Aug 2008
          • 3

          #5
          Hi

          use the following query

          SELECT AUDIT.TRANSACTI ONNO,AUDIT.DATI M, AUDIT.MMNO, AUDIT.COPYS, AUDIT.PRICE,
          MASTER.ITEMNO, MASTER.MTITLE, MASTER.MSRP,
          RETAIL.ITEMNO, RETAIL.MTITLE, RETAIL.MSRP,
          FROM BUYBACKAUDIT AUDIT
          LEFT OUTER JOIN RETAIL ON AUDIT.ITEMNO=RE TAIL.MMBSNO
          LEFT OUTER JOIN MASTER ON AUDIT.ITEMNO=MA STER.MMBSNO

          Thanks
          Nathan
          Hyper Drive
          Bangalore

          Comment

          Working...