Avatar of quarkmike
quarkmikeFlag for France

asked on 

Retrieve number of products per family per category

Hi there,

I have 3 tables

Categories
c_id,
c_name,
c_order

families
f_id,
f_name,
f_order,
f_category

products
p_id,
p_name,
p_price,
p_family


I need to retrieve families who got 1 or more products for all categories and list like this order by c_order,f_order.


<cfoutput group="c_name">
#c_name#<hr>
<cfoutput group="f_name">
#f_name# (number of products for this family)
</cfoutput>
</cfoutput>


Thanks in advance.
Microsoft SQL ServerColdFusion Language

Avatar of undefined
Last Comment
awking00
Avatar of awking00
awking00
Flag of United States of America image

Can you define the key relationships among the three tables?
Avatar of quarkmike
quarkmike
Flag of France image

ASKER

f_category bind to c_id
p_family bind to f_id
ASKER CERTIFIED SOLUTION
Avatar of SANDY_SK
SANDY_SK
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of awking00
awking00
Flag of United States of America image

I think that might work but should add "having count(p_id) > 1" at the end.
Avatar of _agx_
_agx_
Flag of United States of America image

@awkinggoo - I don't think you need it. The inner join does that already. Categories w/o matching products are automatically dropped from the results. Everything else should have at least 1 product.
Avatar of quarkmike
quarkmike
Flag of France image

ASKER

Thx a lot
Avatar of awking00
awking00
Flag of United States of America image

Sorry, I misread >>need to retrieve families who got 1 or more products =<< as
need to retrieve families who got more than 1 product
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo