I have a table called TEST
with 5 columns: clientName, clientID, productNum, orderNum, orderDeliveryDate
, and thousands of rows. It basically stores orders. Each order can be composed of several product items, and each product item can have a specific delivery date.
I need to get a table which shows, for each orderNum
the latest orderDeliveryDate
as well the rest of the TEST
table columns (nb: NULL
values must be excluded because it should not be considered as valid dates).
I know I need to use JOIN, but can't find the solution.
SELECT *
FROM `TEST`
INNER JOIN
(SELECT
orderNum, MAX(orderDeliveryDate) AS maxdate
FROM TEST
GROUP BY orderNum) groupedorders ON TEST.orderNum = groupedorders.orderNum
AND TEST.orderDeliveryDate = groupedorders.maxdate
GROUP BY orderNum
ORDER BY groupedorders.maxdate ASC
Can anyone help me solve this?
Thank you for your help.