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

  • Home
  • SEARCH
  • 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 6617963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:46:00+00:00 2026-05-25T20:46:00+00:00

I have database with several tables in it. For sake of example I will

  • 0

I have database with several tables in it. For sake of example I will simplify it and try to explain in detail.

One table is called Products, another called Brands, and the last one is called Categories.

As you might guessed each Product can have only one Category assigned. Also, each Product can have only one Brand assigned. These are the relationships.

So, on one page I have links with Brands as parameter that I pass to details page where I list all Products from specific Brand. On that page I also have filter by Categories that filters only products from selected Brand by that filter.

E.g. Sony -> then filter applied from drop down is dSLR -> Results of Sony brand dSLR camera products.

What I would like is to have that Categories filtered so that if Brand doesnt have specific category it doesnt even show on that drop down filter.

E.g. Categories are predefined as: dSLR, Video, Cell phone, Shoes

Sony have loads of Products, but doesnt make shoes, so I would like to have it excluded from that filter list on details page.

Hope you understood what I want here…

Any suggestion is more than welcomed 🙂

  • 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-25T20:46:01+00:00Added an answer on May 25, 2026 at 8:46 pm

    Well, you should be able to JOIN the three tables like so:

    SELECT DISTINCT c.category_id, c.category_name
    FROM products p
    JOIN categories c ON p.category_id = c.category_id
    JOIN brands b ON p.brand_id = b.brand_id
    WHERE b.brand_name='Sony';
    

    and then display the products like so:

    SELECT p.product_id, p.product_name
    FROM products p
    JOIN categories c ON p.category_id = c.category_id
    JOIN brands b ON p.brand_id = b.brand_id
    WHERE b.brand_name='Sony' AND c.category_id='1234';
    

    As danishgoel already noted, make sure you have the proper indices on your tables, since this is a quite expensive query.

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

Sidebar

Related Questions

I have a database, with several tables. The main table, called contacts , stores
I have several tables in a database. One table (tbl_transactions) has thousands of orphaned
I have a SQL Mobile database with one table. It has several columns with
I have a SQL Server 2005 database with several tables. One of the tables
I have database with many tables. In the first table, I have a field
I have a database with several tables, 5 of which are dedicated to specific
I have several database tables that just contain a single column and very few
I have a huge database that has several tables that hold several million records.
I have a Ruby on Rails application with a PostgreSQL database; several tables have
I have a database where several tables have a column email for storing email

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.