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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:49+00:00 2026-05-23T03:57:49+00:00

I have a DB structured like this: CATEGORIES > SUBCATEGORIES > PRODUCTS In just

  • 0

I have a DB structured like this:

CATEGORIES > SUBCATEGORIES > PRODUCTS

In just want show the categories which have an number of products related to it, but I don’t know if my method is the best.
I thinking in putting some SELECT statement inside the first WHERE, but this sounds “unpratical”.
I searched into Google/MySQl docs and nothing helped me.

Example of what I have done with CATEGORIES > SUBCATEGORIES:

SELECT c.*
FROM categories c
WHERE 
(
   SELECT count(*)
   FROM subcategories sc
   WHERE sc.id_categories = c.id
) > 2

With this query I can sucessfully see which categories have more than 2 subcategories related to them, I just could do the same, adding the PRODUCTS table to this query. But I almost sure this is going to slow the query. There is some more fast way of doing this type of query?
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-23T03:57:50+00:00Added an answer on May 23, 2026 at 3:57 am

    Something like this, I don’t know your FK relations, so I’m just guessing here.

    SELECT *
    FROM Categories
    WHERE EXISTS(
      SELECT NULL
      FROM products
      JOIN SubCategories ON products.fkSubCatID = SubCategories.PkSubCatID
      WHERE SubCategories.fkCatID = Categories.pkCatID
      HAVING Count(*) > 2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a 3x3 grid layout structured like this: _ _ _
I have a text string structured like this: = Some Heading (1) Some text
I have 2 tables: posts tags Tags table is structured like this: post_id tag
I have an XML file structured like this <serieslist> <series sid=123> <title type=main>Series 123
I have an array that is structured like this: [33] => Array ( [time]
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
Currently I have a structure like this: A | +--B | +--C It's mapped
I have a SVN structure like this: /Projects /Project1 /Project2 /someFolder /Project3 /Project4 I
I have a XML Structure that looks like this. <sales> <item name=Games sku=MIC28306200 iCat=28
If I have a folder structure set up like this: ~/Projects emacs package1 package1-helpers

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.