บทความ > SQL

[SQL] How to query sql for a newest record for each group Turn Back

เมื่อ 2018-09-14 14:47:45

SELECT t.SubcateCode, t.NewsID, t.PrintDate, t.Story, t.Headline
from IRNews t
INNER JOIN (
    SELECT NewsID,SubcateCode, MAX(PrintDate) as MaxDate
    FROM IRNews
    WHERE CategoryCode='EVN'
    GROUP BY SubcateCode
) tm ON t.SubcateCode = tm.SubcateCode AND t.PrintDate = tm.MaxDate
Turn Back

Automotive ดูทั้งหมด

IT Update ดูทั้งหมด