Results 1 to 8 of 8
  1. #1
    Ira is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2011
    Location
    South Florida
    Posts
    21

    Help Using Finding Distinct Value in query

    Hello All,

    Hoping you can help with this query problem I am having.

    Currently running this query:

    SELECT UPSTrackingNumbers.TenderedToDriver, UPSTrackingNumbers.ShipDate, UPSTrackingNumbers.POD, UPSTrackingNumbers.ShippingMethod, UPSTrackingNumbers.VoidIndicator, OrderDetails.ProductCode, OrderDetails.ProductName, Orders.DamagedInTransit, UPSTrackingNumbers.PackageNegotiatedRatesCharge, Orders.Cancelled, Orders.Rep, Orders.AmazonEbayOrderID, Orders.EarliestShipDate, UPSTrackingNumbers.StatusCode, UPSTrackingNumbers.StatusDate, UPSTrackingNumbers.StatusDescription, UPSTrackingNumbers.ShippingService, UPSTrackingNumbers.TrackingNumber, UPSTrackingNumbers.ShippingMethod, UPSTrackingNumbers.Damaged, UPSTrackingNumbers.Delivered, UPSTrackingNumbers.DeliveredDate, UPSTrackingNumbers.TenderedToDriverDate, Orders.DamagedInTransit, Orders.PackedBy

    FROM (UPSTrackingNumbers INNER JOIN Orders ON UPSTrackingNumbers.OrderNo = Orders.OrderID) LEFT JOIN OrderDetails ON Orders.OrderID = OrderDetails.OrderID

    WHERE (((UPSTrackingNumbers.ShipDate) > DateAdd("d", -30, Date())) And ((UPSTrackingNumbers.POD) Is Null) And ((UPSTrackingNumbers.VoidIndicator) <> "Y") And ((UPSTrackingNumbers.StatusCode) = "OC") And ((UPSTrackingNumbers.ShippingMethod) = "FedEx") And (Orders.Cancelled = 0) And (Date() > Orders.EarliestShipDate))

    ORDER BY UPSTrackingNumbers.TenderedToDriver DESC , UPSTrackingNumbers.ShipDate DESC;

    Which gives the result:


    TenderedToDriver ShipDate POD Expr1003 VoidIndicator ProductCode ProductName Expr1007 PackageNegotiatedRatesCharge Cancelled Rep AmazonEbayOrderID EarliestShipDate StatusCode StatusDate StatusDescription ShippingService TrackingNumber ShippingMethod Damaged Delivered DeliveredDate TenderedToDriverDate DamagedInTransit PackedBy
    No 1/30/2023
    FedEx N COM-132 Quality Chemical Oven & Grill Cleaner Heavy-Duty / Fast acti No $25.77 No Amazon 111-0698114-7605063 01/30/2023 OC 01/30/2023 Shipment information sent to FedEx FEDEX_PTP_HOME_DELIVERY 394010384140 FedEx No No

    No Amelia
    No 1/30/2023
    FedEx N QCC-132-4 Oven & Grill Cleaner Heavy-Duty/High Power! Nothing Stronger No $25.77 No Amazon 111-0698114-7605063 01/30/2023 OC 01/30/2023 Shipment information sent to FedEx FEDEX_PTP_HOME_DELIVERY 394010384140 FedEx No No

    No Amelia


    How can I limit the result to give just one distinct tracking number. If you notice, the tracking number [394010384140] is repeated twice.

    Thank you in advance!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You will have to remove the product fields as they are different values, causing 2 records. You cannot expect single records where one or more fields have different data in records that are related to any of the other fields in the result.
    Last edited by Micron; 02-06-2023 at 07:33 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Ira is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2011
    Location
    South Florida
    Posts
    21
    Quote Originally Posted by Micron View Post
    You will have to remove the product fields as they are different values, causing 2 records. You cannot expect single records where one or more fields have different data in records that are related to any of the other fields in the result.

    Can I create a nested query, so I can still have those fields?

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Which of the 2 records would you choose in every case? What's wrong with what you have?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    If you used a report you can group on the tracking number and associated fields and have the product data in the detail section

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You could make the query a totals query and for product code and name fields change the Total row from Group By to Min, Max, First or Last; another option would be to use one of the available concatenation functions to put all product codes for an order in a single field:http://www.accessmvp.com/thedbguy/co...itle=simplecsv

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    It appears that in your example you have ordered 2 items com-132 and QCC-132-4. These 2 items have the same OrderID 111-0698114-7605063. The supplier is sending these as one package by FED EX and since it is 1 package it has 1 TrackingNumber.

    Your query is selecting Items and, since there are 2, you will get a record for each. And each record includes the tracking number, so you get 2.

    You could select Tracking number based on unique OrderId(since there is only 1 OrderId) and not include the item/prod info in the selection.

  8. #8
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    232
    Quote Originally Posted by Ira View Post
    Can I create a nested query, so I can still have those fields?
    Please show us the expected result, to known exactly what you want.
    Groeten,

    Peter

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

Similar Threads

  1. Replies: 6
    Last Post: 05-05-2020, 11:21 PM
  2. Replies: 0
    Last Post: 02-11-2020, 08:12 PM
  3. Replies: 1
    Last Post: 05-22-2018, 07:47 AM
  4. Distinct query
    By mbelote0613 in forum Access
    Replies: 2
    Last Post: 09-28-2016, 03:53 PM
  5. distinct query
    By slimjen in forum Queries
    Replies: 3
    Last Post: 02-04-2012, 04:44 PM

Tags for this Thread

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