Having struggled with using JOINS for some time, i finally managed to write a query without a Syntax Error. However, i need to limit the data it outputs dependant upon the date.
The brief is to select a customer's id, then look at the total number of loyalty points they have redeemed, and also get the LAST DATE they redeemed any. My query works in so far as it will collect customer id, loyalty member id, and number of points, BUT, i get every date they redeemed, and not just the last one.
Is there a way i can make the query only give the last date for a given customer id?
My query is:
SELECT gv.amount AS gv_amount,
gv.customer_id AS gv_customer_id,
h.date AS h_date,
c.loyalty_id AS c_loyalty_id
FROM coupon_gv_customer gv
INNER JOIN loyalty_codes_redeem_history h
ON gv.customer_id = h.customer_id
INNER JOIN customers c
ON gv.customer_id = c.customers_id
h_date is in the format YYYY-MM-DD HH:MM:SS