Reputation: 1659
For example, if my query returns two rows or more, I would like to select the row having the most recent date.
I'm doing something like this:
SELECT * FROM Table1 WHERE Name=Mark AND MAX(TIMESTAMP(date(str_to_date(DATE_REGISTERED,'%d/%m/%Y'))))
The error returned is: #1111 - Invalid use of group function
Upvotes: 0
Views: 132
Reputation: 5236
To limit your results to only the most recent (based on a field named DATE_REGISTERED as per your example) you would do
SELECT * FROM Table1 WHERE Name='Mark' ORDER BY STR_TO_DATE(DATE_REGISTERED,'%d/%m/%Y') DESC LIMIT 1
Upvotes: 2
Reputation: 14032
you should use the order by statement:
SELECT * FROM Table1 WHERE Name=Mark
order by str_to_date(DATE_REGISTERED,'%d/%m/%Y') DESC LIMIT 1
Upvotes: 1