Hi all. I have a VB6 application that accesses data from a MySql table and returns it. One of my columns is time_date that puts a timestamp when data is uploaded. If I have more than one recordset that will be returned, I only want the one with the greatest timestamp. Here is my query:
from item_tracker where reference like ('" & txtReference.Text & "')
group by time_date
The recordset that gets returned is the first one in the table and not the one with the latest timestamp. Can anyone help me so I can return the newest record(max(timestamp))? Thanks.
A recommendation related to your problem is to set "sql_mode" to, among other things, ONLY_FULL_GROUP_BY. This settings requires all columns on which aggregation functions are not applied to be specified in the GROUP BY clause. Your query would have terminated with an error since you did not mention all columns in your GROUP BY. Have a look in the documentation and read about the "modes" to see how you can make MySQL stricter (which prevents you from running some queries that would otherwise give you unexpected results).