Assuming a table like this.
id town_id begin_date
12 2 2011-10-10
23 2 2011-11-10
43 2 2012-01-01
now if I do
SELECT id, MAX(begin_date) AS mx
FROM regions
The above query returns the max date but the id is wrong:
id mx
12 2012-01-01
Is this expected?
How can I get it to return the correct id (43, 2012-01-01)
You forgot the
GROUP BYclause: