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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:55:11+00:00 2026-05-10T18:55:11+00:00

This might be a little hard to explain, but I will try. I want

  • 0

This might be a little hard to explain, but I will try.

I want to display a list of categories (stored in 1 table), and number of domains associated with each category (stored in another table).

The monkey wrench in this case is that each domain has a set of records associated with it (which are stored in a 3rd table). I only want to show the categories that have domains associated with them, and the count of domains should reflect only the domains that have records associated with them (from the 3rd table).

My current query

SELECT r.rev_id, c.cat_id, c.cat_name, count(d.dom_id) As rev_id_count FROM reviews r INNER JOIN  domains d ON r.rev_domain_from=d.dom_id  INNER JOIN  categories c ON d.dom_catid=c.cat_id   WHERE rev_status = 1 GROUP BY cat_name   ORDER BY cat_name 

This selects the correct category names, but shows a false count (rev_id_count). If the category has 2 domains in it, and each domain has 2 records, it will show count of 4, when it should be 2.

  • 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. 2026-05-10T18:55:11+00:00Added an answer on May 10, 2026 at 6:55 pm
    SELECT Categories.Name,count(DISTINCT categories.name) FROM Categories JOIN Domains ON Categories.ID=Domains.CID JOIN Records ON Records.DID=Domains.ID GROUP BY Categories.Name

    Tested with following setup:

     CREATE TABLE Categories (Name nvarchar(50), ID int  NOT NULL IDENTITY(1,1)) CREATE TABLE Domains (Name nvarchar(50), ID int NOT NULL IDENTITY(1,1), CID int) CREATE TABLE Records (Name nvarchar(50), ID int NOT NULL IDENTITY(1,1), DID int)  INSERT INTO Records (DID) VALUES (1) INSERT INTO Records (DID) VALUES (1) INSERT INTO Records (DID) VALUES (2) INSERT INTO Records (DID) VALUES (2) INSERT INTO Records (DID) VALUES (3) INSERT INTO Records (DID) VALUES (3)  INSERT INTO Domains (Name,CID) VALUES ('D1',1) INSERT INTO Domains (Name,CID) VALUES ('D2',1) INSERT INTO Domains (Name,CID) VALUES ('D5',1) INSERT INTO Domains (Name,CID) VALUES ('D3',2) INSERT INTO Domains (Name,CID) VALUES ('D4',2)  INSERT INTO Categories (Name) VALUES ('1') INSERT INTO Categories (Name) VALUES ('2') INSERT INTO Categories (Name) VALUES ('3') 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, this might be a little hard to explain. I'm looking for a way
Okay, this is a little hard to explain, as the title might suggest. I
So, this might be a little bit messy for me to explain, but here
This might be a little bit odd question, but Im trying to figure out
This might be a little bit picky, but in the iPad SplitViewController setup, there
I know this question might be little silly but I can't seem to find
This might be a little hard to follow. I've got a function inside an
This might be a little bit of a stretch, but let's just assume that
I have read about password salting, but this might sound a little odd. But
Ok this might sound a little vague from the title, but that's because 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.