Link to home
Start Free TrialLog in
Avatar of GNOVAK
GNOVAKFlag for United States of America

asked on

SQL: Inner Join Query assist

I have two tables:
Transactions
Products

Products contains an ProductID, Product name as well as other descriptors.  It can have multiple records for the same ID & Product Name.

Transactions contain a ProductID, category and various fields of information based on the sale of specific products.

I'm trying to query the Transactions and retrieve a count of transactions for a specific category along with the Product Name from the Products table.
The count is multiplying the number of records found in the Transaction table by the number of records in the Products table.

How can I correct this?

Query example:

Select Distinct count(a.pProductID)
,B.PRODUCT_NAME
from TRANSACTION_TABLE a
INNER JOIN PRODUCTS B
ON A.PRODUCT_ID = B.PRODUCT_ID
where substr(a.Category,1,6)='WDEFFD'
GROUP BY B.PRODUCT_NAME
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>I'm trying to query the Transactions and retrieve a count of transactions for a specific category along with the Product Name from the Products table.

Agreed.  If a transaction.catetory can be related to multiple products, and needs to return a COUNT() of multiple products, then tell us what logic you want to use to choose amongst the many product names to display in the return set.
Avatar of GNOVAK

ASKER

Helped me put my head on straight with very little caffeine  - Thanks!