开发者

Latest forum posts or replies, with count replies in same query

I want to list latest activity in my forum

UPDATE:

I got this to work now.

SELECT 
    fisk_debat.*, fisk_debat_svar.*, 
    (SELECT dato FROM fisk_debat_svar 
     WHERE debatid = fisk_debat.id 
     ORDER BY dato DESC LIMIT 0,1) AS svardato, 
    (SELECT count(id) FROM fisk_debat_svar 
     WHERE debatid = fisk_debat.id) AS svar 
FROM 
    fisk_debat_svar, fisk_debat 
WHERE 
    fisk_debat.id = fisk_debat_svar.debatid
GROUP BY 
    debatid
ORDER BY 
    svardato DESC, fisk_debat.dato
LIMIT 
    0,15

Now I want to list newly created threads from the forum too and it have to blend into the list like the others. Also ordered by date. Like to different queries merged together. I know UNION but its not the sam开发者_开发技巧e columns.

Need help.


SELECT 
     post.id, 
     post.date, 
     post.header, 
     post.username, 
     COUNT(reply.postid) AS reply, 
     reply.date AS replydate
FROM 
     post AS post
INNER JOIN 
     reply ON post.id = reply.postid 
GROUP BY postid
ORDER BY replydate DESC
LIMIT 0,15

Simply add the sorting order

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜