Gday All,
I am trying to get the details of the first ever transaction for a given customer within a period of time.
Consider the following:
SELECT MIN(t.transaction_date_start), t.*
FROM transactions t
WHERE t.customer_id IN (1,2,3)
AND t.transaction_date_finished >= '2010-02-01 00:00:00'
AND t.transaction_date_finished <= '2010-02-28 23:59:59'
GROUP BY t.customer_id
The above SQL outputs the minimum transaction date correctly however the rest of the data is not what I expect.
It is populated with data of the first grouped customer id not the minimum.
Why is MySQL it outputting data from, effectively, two different queries?
How do I fix my SQL so it selects all the details for the first transaction?
Cheers,
Michael