I would like to ask you that the main table is associated with the child table, and the child table has multiple records, but you only want to get the latest record of the child table (that is, the newly added record).

can you give me a column?

Mar.13,2021

--

-- Table1  Table2  Field1  Field2

-- Table2  AddTime 

SELECT * FROM [Table1] 

WHERE Field1=(
                   SELECT TOP 1 Field2 FROM [Table2] ORDER BY AddTime DESC --AddTime
              )

JOIN twice

 SELECT p.*, c1.*
     FROM parent p
INNER JOIN child AS c1
       ON (p.id = c1.parent_id)
LEFT JOIN child AS c2
       ON (c1.parent = c2.parent_id and c1.createTime < c2.createTime )
    WHERE c2.createTime IS NULL
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e894a6-f42.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e894a6-f42.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?