Here's my situation.
I have a query that returns all orders that are not yet delivered.
This query contains two date fields : Shipping & Delivery.
Shipping can be null or empty. We don't fill this field in certain situations.
Delivery is always a yyyy/mm/dd date, never null, never empty.
Delivery can be in past. We have delays. Today is 05/27 but we are still manufacturing orders that should be delivered a month ago.
Here's some sample data:
I'm trying to write a query based on this query that looks at Shipping and Delivery fields for each customer, and finds/shows the record that contains the smallest date.
This is the above data filtered for Customer1
There are 8 dates and the smallest is 2023/04/22. So the final query should show ONLY the third record (marked in red) for Customer1.
And do the same for other customers. One record per customer that contains the smallest date for that customer (either in shipping or Delivery).
The whole result should be :
I hope I'm clear enough in what I'm trying to do here.
A list grouped by Customers that has the smallest date in either shipping or delivery.
Million thanks.
A small database is attached. To simplify the process, I've changed the query to a table.
Thanks again.
I have a query that returns all orders that are not yet delivered.
This query contains two date fields : Shipping & Delivery.
Shipping can be null or empty. We don't fill this field in certain situations.
Delivery is always a yyyy/mm/dd date, never null, never empty.
Delivery can be in past. We have delays. Today is 05/27 but we are still manufacturing orders that should be delivered a month ago.
Here's some sample data:
Customer | ProductFK | Shipping | Delivery |
---|---|---|---|
Customer1 | 1 | 2025/02/03 | 2025/02/13 |
Customer1 | 4 | 2023/08/12 | 2023/08/13 |
Customer2 | 3 | 2023/06/05 | 2023/06/08 |
Customer3 | 1 | 2023/08/08 | 2023/08/13 |
Customer1 | 3 | 2023/04/22 | 2023/04/25 |
Customer5 | 4 | | 2023/04/18 |
Customer5 | 3 | 2023/07/16 | 2023/07/19 |
Customer3 | 4 | | 2023/08/10 |
Customer2 | 2 | 2023/06/03 | 2023/06/10 |
Customer1 | 2 | | 2024/03/03 |
Customer1 | 1 | | 2023/05/28 |
Customer5 | 2 | | 2023/07/07 |
I'm trying to write a query based on this query that looks at Shipping and Delivery fields for each customer, and finds/shows the record that contains the smallest date.
This is the above data filtered for Customer1
There are 8 dates and the smallest is 2023/04/22. So the final query should show ONLY the third record (marked in red) for Customer1.
And do the same for other customers. One record per customer that contains the smallest date for that customer (either in shipping or Delivery).
The whole result should be :
Customer | ProductFK | Shipping | Delivery |
---|---|---|---|
Customer1 | 3 | 2023/04/22 | 2023/04/25 |
Customer2 | 2 | 2023/06/03 | 2023/06/10 |
Customer3 | 1 | 2023/08/08 | 2023/08/13 |
Customer5 | 4 | 2023/04/18 |
I hope I'm clear enough in what I'm trying to do here.
A list grouped by Customers that has the smallest date in either shipping or delivery.
Million thanks.
A small database is attached. To simplify the process, I've changed the query to a table.
Thanks again.
Attachments
Last edited: