First, the problem scenario
A table has a key field tid,action,dateline, etc., the TID represents the id,action of the Post, which represents the status of the post being manipulated, Dateline represents the timestamp of the data being inserted;
In this table, each TID will have several different Dateline inserted details, the last time the action field in the detail inserted indicates the status of the current Tid's post;
Now you want to query the current status of each tid, that is, to query the latest published record
Sample Data in table:
Second, SQL statement:
Select A.* from Pre_forum_threadmod as A, (select Tid,max (Dateline) as Dateline from Pre_forum_threadmod Group by Tid) as B where A.tid=b.tid and A.dateline=b.dateline
Third, SQL statement parsing:
In the above SQL statements, the largest dateline of each TID is identified, and the query generates a temporary table B;
(select Tid,max (Dateline) as Dateline from Pre_forum_threadmod Group by Tid) as B
Then the original table A and temporary Table B Association query can:
where A.tid=b.tid and A.dateline=b.dateline
After enquiry, for example, the latest record of each TID can be found: