Results 1 to 4 of 4
  1. #1
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31

    Query only shows record if there are matching items in a linked table

    Table 1: PurchaseOrders
    This table contains simple meta-data about a PO.

    Table
    2: OrderedItems
    Contains items that are on the purchase orders. Linked by PO Number (primary key for the PurchaseOrders table). Includes details like tax, shipping, cost, etc.

    Table 3: A lookup table that contains vendors
    This table contains simple meta-data about a PO.

    Query 1: qryOrderWithVendors
    This Query is based on Purchase Orders and brings in the sum of the tax, shipping, etc. dollar amounts so I can say, "The total for PO 123 is $84.19" without needing to do any calculations.



    My Problem
    When I run the query, it only brings in purchase orders that have associated items that have been sold. It does not display anything that doesn't have any items yet. I would like it to show them as $0.

    The Code
    Code:
    SELECT DISTINCT PurchaseOrders.ID, PurchaseOrders.PODT, PurchaseOrders.DateOrdered, PurchaseOrders.OrderedBy, Vendors.VendorName, Sum(OrderedItems.[UnitCost]*OrderedItems.Quantity) AS NetCost, Sum([OrderedItems].[UnitShipping]*[OrderedItems].[Quantity]) AS Shipping, Sum([OrderedItems].[UnitTax]*[OrderedItems].[Quantity]) AS Tax, Sum(OrderedItems.LineCost) AS OrderCost
    FROM Vendors INNER JOIN (PurchaseOrders INNER JOIN OrderedItems ON PurchaseOrders.ID = OrderedItems.PONumber) ON Vendors.ID = PurchaseOrders.Vendor
    GROUP BY PurchaseOrders.ID, PurchaseOrders.PODT, PurchaseOrders.DateOrdered, PurchaseOrders.OrderedBy, Vendors.VendorName;
    Please help!

    Thank you,

    Dan

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In design view of the query, right-click on the line joining fields together to edit the join. You'll see your available options. In SQL view, that's the equivalent of changing INNER to RIGHT or LEFT as appropriate.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    You, sir are a miracle worker. Here's the new SQL that, of course, works like a dream:

    Code:
    SELECT DISTINCT PurchaseOrders.ID, PurchaseOrders.PODT, PurchaseOrders.DateOrdered, PurchaseOrders.OrderedBy, Vendors.VendorName, Sum(OrderedItems.[UnitCost]*OrderedItems.Quantity) AS NetCost, Sum([OrderedItems].[UnitShipping]*[OrderedItems].[Quantity]) AS Shipping, Sum([OrderedItems].[UnitTax]*[OrderedItems].[Quantity]) AS Tax, Sum(OrderedItems.LineCost) AS OrderCost
    FROM Vendors INNER JOIN (PurchaseOrders LEFT JOIN OrderedItems ON PurchaseOrders.ID = OrderedItems.PONumber) ON Vendors.ID = PurchaseOrders.Vendor
    GROUP BY PurchaseOrders.ID, PurchaseOrders.PODT, PurchaseOrders.DateOrdered, PurchaseOrders.OrderedBy, Vendors.VendorName;
    Thanks!

    Dan

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. best way to find a record in a linked table
    By BRV in forum Programming
    Replies: 14
    Last Post: 11-10-2011, 09:31 AM
  2. Lock Record for Editing on a Linked table
    By khalid in forum Programming
    Replies: 3
    Last Post: 06-14-2011, 08:37 AM
  3. List in Report Shows All Items in Table, But I Only Want...
    By italianfinancier in forum Programming
    Replies: 1
    Last Post: 05-28-2011, 02:42 AM
  4. Replies: 5
    Last Post: 10-15-2010, 01:19 PM
  5. Replies: 2
    Last Post: 10-27-2009, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums