I have a table called myTable which is like this:
id, myDate, name, group
1, 2012-04-09, john, subGroup-A
2, 2012-04-10, marc, subGroup-B
I would like to retrieve the record with the maxDate and the name that goes with it, for the subGroup that starts with ‘subGroup’. So I am doing the following query:
SELECT max(myDate) AS maxDate, name FROM myTable WHERE group LIKE "subGroup%";
I would expect this query to return me this:
maxDate, name
2012-04-10, marc
But instead it is returning me this:
maxDate, name
2012-04-10, john
So basically the maxDate is taken correctly, but the name is not the one corresponding to that date. I really do not get it. Hope someone can help me understand. Thank you in advance for your replies. Cheers. Marc
Your query is:
I think you need the following:
or