Skip to content

Instantly share code, notes, and snippets.

@lordmatt
Created May 4, 2013 23:47
Show Gist options
  • Save lordmatt/5519190 to your computer and use it in GitHub Desktop.
Save lordmatt/5519190 to your computer and use it in GitHub Desktop.
This is an SQL query that will return both the NucleusCMS comment but also the ModComment values all in one hit. This is as part of a side project to make certain comment related functions more sophisticated.
SELECT nucleus_comment.*,count(recordID) as votes,sum(score) as score, TopScore
FROM nucleus_comment
INNER JOIN nucleus_plugin_modcomments
ON nucleus_plugin_modcomments.commentid=nucleus_comment.cnumber
INNER JOIN
(
SELECT *
FROM (
SELECT commentid, COUNT( recordid ) AS freq, score AS TopScore
FROM nucleus_plugin_modcomments
GROUP BY commentid, score
) AS FR1
GROUP BY commentid, TopScore
HAVING freq = MAX( freq )
) AS T1
ON T1.commentid=nucleus_comment.cnumber
GROUP BY nucleus_comment.cnumber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment