简体   繁体   中英

MySQL error Reatest-n-per-group

Help me!

       SELECT ma_forum.*, ma_forum_cat.*

        FROM ma_forum, ma_forum_cat

        JOIN ma_forum_comentarios ON ma_forum_comentarios.not_id = ma_forum.not_id

        GROUP BY ma_forum.not_id

        WHERE ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='".$notcat_id."' 

        AND ma_forum.not_status='Ativo'

        ORDER BY MAX(ma_forum_comentarios.comnot_data) DESC

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='1' ' at line 9"

Your query is in the wrong order; GROUP BY should be after WHERE and before ORDER BY:

SELECT ma_forum.*, ma_forum_cat.*
FROM ma_forum, ma_forum_cat
JOIN ma_forum_comentarios ON ma_forum_comentarios.not_id = ma_forum.not_id
WHERE ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='".$notcat_id."' 
AND ma_forum.not_status='Ativo'
GROUP BY ma_forum.not_id
ORDER BY MAX(ma_forum_comentarios.comnot_data) DESC

I don't know what database you're using, but here's a link to MySQL's SELECT syntax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM