Select query problem (1 Viewer)

npa3000

Member
Local time
Today, 04:51
Joined
Apr 16, 2021
Messages
36
Hello,

I have a table called "LOADINGS". In that table there are informations about the loadings of orders.(Some orders have a lot of loadings)

For example some rows:
1642606075341.png


I want to create a query that shows me the LAST Loading Date of an order for all orders.

F.e. for the order 20220160 i must take "10/1/2022" but fot order 20220163 i have to take 13/1/2022.

I have created this query, but it shows me all the records. I know that something is missing but i cannot find that. Do you have any idea?
Code:
SELECT DISTINCT LOADINGS.ORDER_ID, LOADINGS.LOADING_DATE
FROM LOADINGS
ORDER BY LOADINGS.LOADING_DATE DESC;
 

Ranman256

Well-known member
Local time
Yesterday, 21:51
Joined
Apr 9, 2015
Messages
4,337
Q1,turn on grouping sums to get the max date:
select Max(LoadingDate), OrderID from table

now that you have the max date, get the rest of the data, using Q1 joined to the table:
Q2: select * from table, Q1 where Q1.Date = table.Date and Q1.OrderID = table.OrderID
 

plog

Banishment Pending
Local time
Yesterday, 20:51
Joined
May 11, 2011
Messages
11,643
To get what you want this is the SQL:

Code:
SELECT OrderID, MAX(LoadingDate) AS LastLoadingDate FROM LOADINGS GROUP BY OrderID
 

Users who are viewing this thread

Top Bottom