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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:56:42+00:00 2026-05-11T13:56:42+00:00

I need to filter products where certain attributes are stored in a joined table

  • 0

I need to filter products where certain attributes are stored in a joined table that match all the required properties, i.e. users need to be able to gradually narrow down their search by adding requirements.

The problem really just concerns the properties table I think, rather than the join, given the following (simplified) table of product properties:

 id  product_id  property  value --------------------------------- 1   1           color     red 2   1           size      small 3   2           color     red 4   2           size      large 

how would I get all the product_ids where value is both ‘red’ and ‘small’ ?

A similar question was asked before but not answered very fully. A solution involves a COUNT and HAVING to get the rows where there are as many rows in each group as required values e.g.

SELECT product_id, count(*) AS group_count FROM properties where value = 'red' OR value = 'small' GROUP BY product_id HAVING group_count = 2 

This works but I’m concerned about performance, it seems like there would be a better way.

Eventually this would need to be joined with, or at least used to filter the products table:

 id  name      ------------- 1   Product 1 2   Product 2 

I forgot to mention that I have 2 of these properties tables joined to products that I need to filter on, one with regular attributes of a product, another with available configurable options (a bit like variants). The scenario is to allow users to filter products like: ‘show products where gender = ‘male’, brand = ‘nike’ and size == ‘small” where gender and brand are ‘properties’ and size is in options (configurable when adding to cart)

The solution of using a group with a count works with the 2 joined tables still but it gets messy, the required group count is the number of required options on the first table multiplied by the number on the second.

I could just fetch the ids from properties (and the other table) then just do a select where id IN(ids), matching a set of ids for both property tables, I don’t like the idea of doing this with a really long list of ids though.

  • 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-11T13:56:43+00:00Added an answer on May 11, 2026 at 1:56 pm

    Not sure this is faster, but joins from subqueries generated from your filter criteria would work:

    Select p.name, p.id from product p,  (select product_id from properties where value='red') colors, (select product_id from properties where value='small') sizes where p.id=colors.product_id and p.id=sizes.product_id 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 259k
  • Answers 259k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Per the docs, the exec statement takes two optional expressions,… May 13, 2026 at 11:12 am
  • Editorial Team
    Editorial Team added an answer This should do it: int n = 12345; int left… May 13, 2026 at 11:12 am
  • Editorial Team
    Editorial Team added an answer Yes, you can have track data into multiple GA profiles… May 13, 2026 at 11:12 am

Related Questions

I have a two tables as follows: product category(t1): id name product master(t2): id
I am working with a LINQ to SQL query and have run into an
I have an application where I need to parse or tokenize XML and preserve
The structure of the table testtable is id int primary key productid int attributeid

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.