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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:33:53+00:00 2026-05-23T20:33:53+00:00

I have the following table: categories: cat_id | cat_cat | cat_name 1 | 0

  • 0

I have the following table:
categories:

cat_id | cat_cat | cat_name
     1 |       0 | name1
     2 |       0 | name2
     3 |       1 | name3
     4 |       2 | name4
     5 |       2 | name5
     6 |       0 | name6
     7 |       1 | name7

I am trying to select all the categories with cat_cat=0, and selecting a count of every record that has cat_cat as the current cat_id, essentially giving me the following result:

cat_id | cat_cat | cat_name | cat_subcats
     1 |       0 | name1    |           2
     2 |       0 | name2    |           2
     6 |       0 | name7    |           0

I have tried multiple queries and my current one is as follows:

SELECT i.* , COUNT( i2.icon_id ) AS subcats
FROM themes_icons i, themes_icons i2
WHERE i.icon_cat =  '0'
    AND i2.icon_cat = i.icon_id
GROUP BY i.icon_cat, i2.icon_id
ORDER BY i.icon_order ASC

This query seems to give me the following results:

cat_id | cat_cat | cat_name | cat_subcats
     1 |       0 | name1    |           1
     1 |       0 | name1    |           1
     2 |       0 | name2    |           1
     2 |       0 | name2    |           1
     6 |       0 | name7    |           0

Anyone know how I can get the desired results. I’ve tried join statements too, but they keep giving me back errors.

Thanks in advance.

  • 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-23T20:33:53+00:00Added an answer on May 23, 2026 at 8:33 pm
    SELECT c1.cat_id, c1.cat_cat, c1.cat_name,
    (
      SELECT COUNT(*)
      FROM categories c2
      WHERE c2.cat_cat=c1.cat_id
    ) AS cat_subcats
    FROM categories c1
    WHERE c1.cat_cat=0
    

    Its a standard SELECT, except the subselect that counts the subcategories for the current category.

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

Sidebar

Related Questions

I have a cat table that has the following columns: cat_id | name |
I have basically the following table, Categories id name categories_id_categories 1 Clothes null 2
I have the following tables: CATEGORIES -- entry_id, cat_id TITLES -- entry_id, title DATA
I have the following tables: Table categories { -id- -name- 1 Action 2 Comedy
I have a database with the following tables: create table Categories ( Id int
I have following table Id | Status | date ------------------- 1 | Onsite |2007
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
I have the following table. When i try to insert records using LINQ to
I have the following table of TIME datatypes clarification: I am representing hours/mins/seconds of
I have the following table EVENT_LOG : EVENT_ID: pk, int, not null TYPEID: fk,

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.