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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:20:17+00:00 2026-05-18T00:20:17+00:00

I am designing a custom blog in PHP. On my panel I have the

  • 0

I am designing a custom blog in PHP. On my panel I have the heading “Categories” and I list the categories and how many posts are in each category. There are 2 related tables, posts, and post_categories.

POSTS – post_id, post_title, post,
category_id

POST_CATEGORIES – category_id,
category_name, post_id

I’d prefer not to add a category of uncategorised as this will cause me issues with future features I plan to design. My SQL for this is:

SELECT *, COUNT(*) AS category_post_count
FROM post_categories, posts
WHERE posts.category_id = post_categories.category_id
GROUP BY category_name

Now if a post is not set with a category_id, it is given a category_id of 0 and will not related to anything in post_categories. How can I group these in my SQL statement AS uncastegorised?

Thanks.

  • 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-18T00:20:18+00:00Added an answer on May 18, 2026 at 12:20 am

    You can do a left join to also include any posts that don’t have a category.

    SELECT *, COUNT(*) as category_post_count
    FROM post_categories LEFT JOIN posts
      ON posts.category_id = post_categories.category_id
    GROUP BY category_name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing some custom blog software, and have run into a conundrum regarding database
I have two TextFields and I am designing a custom keyboard for ipad. How
I am designing XML for some custom logging. There's a part in the logger
I am working in android. i am designing a custom dialog in which there
I'm designing an iPad app that will have a custom grid in it. The
I am designing a custom button with that requires me to overlay a UIButton
I am designing a custom widget which is basically a QGroupBox holding a configurable
I am designing a custom HTML helper and I would like to execute Html.ActionLink
I am creating a custom Table by designing my own UITableViewCell in Xcode and
Defining custom components in Facelets is easy and quick but there's one thing I

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.