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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:42:00+00:00 2026-05-27T20:42:00+00:00

I am having trouble with drilling down some data, this is the table structure

  • 0

I am having trouble with drilling down some data, this is the table structure

Products Table

uid_product (unique id)

txt_prod_name (product name)

Table Name: tbl_products

Product Features

uid_feature(unique id)

txt_feature_name(feature name)Table Name: tbl_features

Assigned Product Features

uid_prodf (unique id)

uid_prodf_prodid (foreign key to uid_product)

uid_prodf_featid(foreign key to the uid_features)

Table Name: tbl_prod_features

One product can have many features hence the use of the tbl_prod_features table.

I have created the following query, to obtain the results;

<cfquery name="getFeatureProducts" datasource="#application.dsn#">
SELECT uid_product, txt_prod_name
FROM dbo.tbl_products
WHERE uid_product IN (SELECT (dbo.tbl_product_features.uid_prodf_prodid)
FROM dbo.tbl_product_features
WHERE  uid_prodf_featid IN (<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.uid_features#" list="yes">))
ORDER BY dbo.tbl_products.txt_prod_name
</cfquery>

This works great for getting all products associated to the features selected by the end user. However what I need to achieve is the following,

If a user selects;

Feature A = 5 products displayed (3 out of 5 of these products contains Feature B)

If the user then selects;

Feature B = 3 Products

Currently with the query using the in operator it will still retrieve 5 products.

My first thoughts was to create a dynamic where statement adding the AND operator, however uid_prodf_featid = 5 AND uid_prodf_featid = 6 will always produce 0 results.

My second idea was to build an array of product id’s from the first drill down i.e. get the id’s of the first 5 products, and pass them in to the query and then drill down the features, this works and the correct results are obtained.

However the user has the ability to remove features (and in any order), so I would somehow need to keep track of the products id’s as and when they were added and removed.

I am sure I am overcomplicating this, but any help would be appreciated.

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

    Use a HAVING clause to count the number of matching features and return only products that have all of the requested features.

    For example, if arguments.uid_features always contains unique feature id’s, you could do something like this:

    SELECT p.uid_product, p.txt_prod_name
    FROM   tbl_products p  INNER JOIN tbl_product_features f 
               ON p.uid_product = f.uid_prodf_prodid
    WHERE  f.uid_prodf_featid IN ( <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.uid_features#" list="true"> )
    GROUP BY p.uid_product, p.txt_prod_name
    HAVING COUNT(f.uid_prodf_featid) = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ListLen(arguments.uid_features)#">
    ORDER BY p.txt_prod_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
Having trouble looping through multiple rows in a SQL table and getting the info
Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key =
Having trouble with this -- a couple of other related posts out there, but
Having trouble rewriting the name of a flash file: /flash/shell.1257347618.swf (the numbers are a
Having trouble with some select statements. I have 2 tables. sms_log and sms_messages. sms_log
im having trouble extracting the trend name and search query from the json response
having trouble coming up with search parameters for this issue, so I can't find
Having trouble finding a solution for my situation here. Sorry if this has been
Having trouble inheriting from a template class. Looks something like this: template<typename type> class

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.