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 7367909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:35:50+00:00 2026-05-29T03:35:50+00:00

So I have a simple data structure: blog_entries id | category | title |

  • 0

So I have a simple data structure:

blog_entries

 id | category | title | body | desc| date

blog_comments

 id | entry_id | author | email | website | body | date

I am trying to LEFT JOIN blog_comments ON entry_id to get teh COUNT on comments for each entry. I only have two records in ‘blog_entries’ and none in ‘blog_comments’ ATM. For some reason when I run the query below, I only get one result back:

SELECT
    blog_entries.*,
    COUNT(blog_comments.id) AS comment_count        
    FROM blog_entries
        LEFT JOIN blog_comments 
            ON blog_entries.id = blog_comments.entry_id

I do not understand why my LEFT table is not being preserved.

  • 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-29T03:35:50+00:00Added an answer on May 29, 2026 at 3:35 am

    Your left table is not being preserved, because according to: Group by functions

    If you use a group function in a statement containing no GROUP BY clause, it is equivalent to grouping on all rows.

    You should use:

    SELECT
        blog_entries.*, 
        COALESCE( c.cnt, 0 ) as comment_count
    FROM blog_entries
    LEFT JOIN 
      ( SELECT entry_id, COUNT(*) as cnt
        FROM blog_comments
        GROUP BY entry_id ) c
    ON blog_entries.id = c.entry_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple data model of two tables, email and recipients, email can
I have a simple data structure which is serialized and deserialized. Upon deserialization, I
I have a very simple data structure that I have defined in Lisp: ;;Data
Say you have a very simple data structure: (personId, name) ...and you want to
I am using Delphi 2009. I have a very simple data structure, with 2
I have a simple data structure (the properties are of course Dependency Properties): class
I have a fairly simple data.frame dput(x), below: x <- structure(list(variable = c(a, b,
I have only simple data types in method signature of service (such as int,
I have a simple WCF Data Services service and I want to expose a
I have simple SSIS package which reads data from flat file and insert into

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.