MySQL har ikke nogen rangeringsfunktionalitet, men du kan bruge en variabel til at oprette et psuedo-rækkenummer.
Brug:
SELECT x.*
FROM (SELECT cm.id,
cm.title AS cmtitle,
cm.sectionid,
cm.type AS cmtype,
cd.id AS cd_id,
cd.time,
cd.link,
cd.title,
cd.description,
cd.sectionid AS cd_sectionid,
CASE
WHEN @sectionid != cm.sectionid THEN @rownum := 1
ELSE @rownum := @rownum + 1
END AS rank,
@sectionid := cm.sectionid
FROM C_MAIN cm,
C_DATA cd,
(SELECT @rownum := 0, @sectionid := NULL) r
WHERE cm.sectionid = cd.sectionid
ORDER BY cm.sectionid) x
WHERE x.rank <= 20
ORDER BY id