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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:09:02+00:00 2026-05-28T20:09:02+00:00

I am trying to get the correct result from a query and am having

  • 0

I am trying to get the correct result from a query and am having some difficulty, my products are shown via their category, sub-category and associated categories. Associated categories are where the user can associate products with a secondary category (for similar products).

The data is being drilled down by product features e.g swings or slides etc.

The result of a features drill down should be that if Swings is selected, only products within the selected category, subcategory or associated category with Swings should be displayed.

The end user can then click on another feature, e.g. Slides, and the results should be only products within its selected category, subcategory or associated category with swings AND slides.

The following query gets me products with associated categories (this works fine) using a nested query:

<cfquery name="getProductList" datasource="#application.dsn#">
SELECT 
  p.uid_product,
  p.txt_prod_name,
  p.uid_prod_templteid,
  p.txt_prod_metaurl,
  p.txt_prod_h1,
  p.txt_prod_ref,
  p.mon_prod_rrp,
  p.mon_prod_current,
  i.txt_pimg_name,
  i.uid_pimages,
  i.txt_pimg_alt
FROM dbo.tbl_products
  IINNER JOIN tbl_product_images i ON (p.uid_product = i.uid_pimg_prodid)
  WHERE p.uid_prod_webid=<cfqueryparam cfsqltype="cf_sql_integer" value="#application.webid#">
  <!---If! If arguments to uid_subcategory is defined: USAGE! Get sub cats--->
  <cfif Isdefined('arguments.uid_subcategory') AND arguments.uid_subcategory NEQ "">
  AND p.uid_prod_subcatid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.uid_subcategory#"></cfif>
  AND dbo.tbl_product_images.bit_pimg_primary=<cfqueryparam cfsqltype="cf_sql_bit" value="yes">
  <cfif Isdefined('arguments.uid_categories') AND arguments.uid_categories NEQ "">
  AND p.uid_prod_catid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.uid_categories#"> OR
  <!---QUERY! Look for associated categories and deliver product to the page--->
  uid_product IN (SELECT (ac.uid_assoc_prodid)
  FROM tbl_assoc_categories ac
  WHERE ac.uid_assoc_catid=<cfqueryparam cfsqltype="cf_sql_integer" value="#uid_categories#">
  <!---If! If the user selects a subcategory we only want the associated products directly linked to the chosen sub category --->
  <cfif Isdefined('arguments.uid_subcategory') AND arguments.uid_subcategory NEQ "">
  AND ac.uid_assoc_subcatid=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.uid_subcategory#"></cfif>)</cfif>
  ORDER BY txt_prod_name asc
</cfquery>
      <cfreturn getProductList>
    </cffunction>

The following query is what i use to drill down the products using features:

<cfquery name="getFeatureProducts" datasource="#application.dsn#">
SELECT 
  p.uid_product,
  p.txt_prod_name,
  p.uid_prod_templteid,
  p.txt_prod_metaurl,
  p.txt_prod_h1,
  p.txt_prod_ref,
  p.mon_prod_rrp,
  p.mon_prod_current,
  i.txt_pimg_name,
  i.uid_pimages,
  i.txt_pimg_alt
FROM tbl_products p
INNER JOIN tbl_product_images i ON (p.uid_product = i.uid_pimg_prodid)
INNER JOIN tbl_product_features f ON (p.uid_product = f.uid_prodf_prodid)
WHERE  0=0
AND f.uid_prodf_featid IN (<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.uid_features#" list="yes">)
GROUP BY p.uid_product, p.txt_prod_name, p.uid_product, p.txt_prod_name, p.uid_prod_templteid, p.txt_prod_metaurl, p.txt_prod_h1, p.txt_prod_ref,p.mon_prod_rrp,p.mon_prod_current,i.txt_pimg_name,i.uid_pimages,i.txt_pimg_alt
HAVING COUNT(f.uid_prodf_featid) = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ListLen(arguments.uid_features)#">
ORDER BY p.txt_prod_name
</cfquery>

At the moment the query above returns all the products without taking into account categories, sub-categories or associated categories. I need to be able to add the functionality of the first query into the second query. I can do the category and subcategory fine just by adding an isdefined and an sql AND statement; it’s the associated categories I’m struggling with. Not sure how to add the nested query to the WHERE clause and still keep the query working, I have tried playing around with but just didn’t work as it always gives the wrong results.

Any help is 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-28T20:09:03+00:00Added an answer on May 28, 2026 at 8:09 pm

    I’ve setup an example query on my site, sqlfiddle.com, which demonstrates your question (and my answer): http://sqlfiddle.com/#!3/8d051/2

    Here’s the meat of it, including the CF code:

    SELECT 
      p.uid_product,
      p.txt_prod_name,
      p.uid_prod_templteid,
      p.txt_prod_metaurl,
      p.txt_prod_h1,
      p.txt_prod_ref,
      p.mon_prod_rrp,
      p.mon_prod_current,
      i.txt_pimg_name,
      i.uid_pimages,
      i.txt_pimg_alt
    FROM tbl_products p
     INNER JOIN tbl_product_images i ON (p.uid_product = i.uid_pimg_prodid)
      <cfloop list="#arguments.uid_features#" index="featid">
      INNER JOIN tbl_product_features f#featid# ON
        f#featid#.uid_prodf_prodid = p.uid_product AND
        f#featid#.uid_prodf_featid = <cfqueryparam value="#featid#" cfsqltype="cf_sql_integer">       
      </cfloop>
    
    ORDER BY
      p.txt_prod_name
    

    This method uses joins to filter the result set, and the cfloop to do so once per feature. This should work.

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

Sidebar

Related Questions

I am trying to make one query, to get some statistic data from database.
Im trying to query a List but unable to get the result the way
I am trying to display some data from mySQL, the db details are correct
I'm trying to get insights from facebook for some pages I have admin rights
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to get my mind around google protobuf. I found some implementation of protobuf
I'm trying to get a query going that will search multiple tags. The tags

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.