I'm not sure if this sounds like possible with SQL: I've two tables, among content, each by having an integer ID, along with a table of comments each by having an "On" area denoting this content it's on. Let me get the content so as of the number of comments get it within their "On" area, and was wishing SQL could get it done.
SELECT comment.on AS content_id, COUNT(comment_id) AS num_comments FROM comments GROUP BY content_id ORDER BY num_comments DESC
If you want all of the fields from the content, you are able to perform a join:
SELECT contents.*, COUNT(comment_id) AS num_comments FROM contents LEFT JOIN comments on contents.content_id = comments.on GROUP BY content_id ORDER BY num_comments DESC
select c.id, count(cmt.*) as cnt from Content c, Comment cmt where c.id = cmt.id order by cnt group by c.id,
Let us assume your tables seem like this (I authored this in pseudo-SQL - syntax may vary based on database you're using). In the description you provided, it's not obvious the way you are joining the tables. Nonetheless, It looks something similar to this (using the caveat that primary secrets, indexes, and so on are missing):
CREATE TABLE [dbo].[Content] ( [ContentID] [int] NOT NULL, [ContentText] [varchar](50) NOT NULL ) CREATE TABLE [dbo].[ContentComments] ( [ContentCommentID] [int] NOT NULL, [ContentCommentText] [varchar](50) NOT NULL, [ContentID] [int] NOT NULL ) ALTER TABLE [dbo].[ContentComments] WITH CHECK ADD CONSTRAINT [FK_ContentComments_Content] FOREIGN KEY([ContentID]) REFERENCES [dbo].[Content] ([ContentID])
This is how you'd write your query to obtain the content sorted by the amount of comments each bit of content has. The DESC sorts this content products from individuals most abundant in comments to individuals using the least comments.
SELECT Content.ContentID, COUNT(ContentComments.ContentCommentID) AS CommentCount FROM Content INNER JOIN ContentComments ON Content.ContentID = ContentComments.ContentID GROUP BY Content.ContentID ORDER BY COUNT(ContentComments.ContentCommentID) DESC