Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:25:20+00:00 2026-05-29T12:25:20+00:00

I have 2 tables : review (including content_type_id , object_id ) comments (including content_type_id

  • 0

I have 2 tables :

  • review (including content_type_id , object_id )
  • comments (including content_type_id , object_id )

The combination of “content_type_id and object_id” uniquely defines an entity (like article etc)


Now i want to write a single SQL Query to :

“list all the articles with their ‘review_count’ and ‘comment_count’ “.

I mean in final result , what i want is :

content_type_id | object_id | review_count | comment_count

How can i acheive this..??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:25:23+00:00Added an answer on May 29, 2026 at 12:25 pm

    (Edited after question changed and I found a data-bug)

    Try this one:

    select 
        content_type_id, object_id,
        sum(review_count) review_count,
        sum(comment_count) comment_count
    from
        (
            select 
                content_type_id, object_id, count(*) review_count 
            from jc_reviews 
            group by 1, 2
        ) as r_count
        full outer join 
        ( 
            select content_type_id, object_id, count(*) comment_count 
            from jc_comments 
            group by 1, 2
        ) as c_count
        using (content_type_id, object_id)
    group by 1, 2
    

    It does not use a central table (formerly called article). This means, that items without any comment and without any review will not show up in the result. Items where at least one comment or one review is there will show up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables, that look like: CustomerInfo(CustomterID, CustomerName) CustomerReviews(ReviewID, CustomerID, Review, Score) I
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
I have three tables: page, attachment, page-attachment I have data like this: page ID
I have 2 tables one called REVIEW and the other REVIEW_DESCRIPTION If I do
I have three tables in my database. News, reviews and tutorials. I would like
I have to related tables like in the example script below: -- Creating table
I have 2 tables: user_tb.username user_tb.point review_tb.username review_tb.review I am coding with PHP(CodeIgniter). So
In my SQL I have 2 tables: film = filmid, filmname and review =
I have tables of venues, reviews and comments where a venue can have many
I have 3 tables structured like so: activity table: activity_id, user_id, type, date reviews

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.