I have two data tables. The first table called ClientDE has two primary keys - ClientID and LastPurchaseDate. The second table called LastPurchaseDE has one primary key - ClientID. The second table is populated with data from ClientDE and should have only the latest purchase.
I use this SQL code:
SELECT a.clientId, a.LastPurchaseDate, a.PurchaseName
FROM
(SELECT DISTINCT g.clientID, MAX(g.LastPurchaseDate), g.PurchaseName
FROM ClientDE g
GROUP BY g.clientID, g.PurchaseName) a
WHERE a.PurchaseName LIKE 'SHOP%'
ClientDE can have few records with the same ClientID and different date, I want to populate LastPurchaseDE only with the MAX date for the client. This SQL should retrieve unique values, but it doesn't