.what i want to do is to retrieve records from my database and display everything but the condition is not to display all records having the same task_id but to display only the newest among them. how do I select the newest among the records with the same task_id?
Share
You will need a column like
so each time a row is inserted, or updated, the
last_modifiedcolumn gets updated with the current timestamp. Then, all you need is a query likeWill fetch the latest 5 updated tasks from the database with the given
task_id. Remove theWHEREclause to get the newest tasks regardless of thetask_id.note: the
TIMESTAMPdata type is special, in the sense that MySQL will update the field automatically, by default, to the current timestamp, unless a value is explicitly defined in the insert or update query. If this behavior is not wanted, useDATETIME, but it will require that you specify the column value for the new column (unless a default value is set in the table)