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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:51:02+00:00 2026-05-12T09:51:02+00:00

I have two tables: CATEGORY and SUBCATEGORY Table Structure for CATEGORY category_id int(11) category_name

  • 0

I have two tables: CATEGORY and SUBCATEGORY

Table Structure for CATEGORY

category_id         int(11)  
category_name       varchar(250) 
category_status     enum('0', '1')

Table Structure for SUBCATEGORY

subcategory_id      int(10) 
subcategory_name    varchar(255)    
status              enum('0', '1')

For example there is a single CATEGORY named .NET and it has entries in SUBCATEGORY like ASP.NET, VB.NET, C#.NET . In this case I need to get the count of CATEGORY as 1 and the count of SUBCATEGORY as 3 using MySQL.

How can I accomplish this?

  • 1 1 Answer
  • 2 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-12T09:51:03+00:00Added an answer on May 12, 2026 at 9:51 am

    Well, you can do it with a subquery. However, you’ll need to add a category_id column to the subcategory table, so that we know what subcategories go with which categories. Then, you can get what you want with the following query:

    select
        category_name,
        1 as CategoryCount,
        (select count(*) from subcategory where category_id = c.category_id) as SubCategoryCount
    from
        category c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two tables product product_id product_Name product_Price product_Description product_image category_id another table category
My prob in brief: I have two tables namely category and product. table: category
I have those two tables: client: id (int) #PK name (varchar) client_category: id (int)
I have two tables: [ product_to_category --------------------- product_id category_id [ category --------------------- category_id parent_id
Okay so I have two tables, a category table and a posts table. I
I have two tables, one with categories and subcategories. Each category and subcategory has
I have two tables, one is a table of names with a category tag
I have n:m table which links data between two tables: id | category -------------
I have two tables in a Mysql database. PACKAGES: ID (auto_increment) CATEGORY (INT) NAME
Let's say I have two tables: Category and Product , and Product links to

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.