Query Help

jeancake

Board Regular
Joined
Nov 3, 2008
Messages
57
Hello,

I have a sales transaction table that tracks products sold at different channel (in store, web, & telephone). The channel is identified using a channel id(1,2,3). I would like a query that would show me a unique list of products that were sold in all three channels. I've tried:

SELECT ProductID
FROM SalesTransaction
where ChannelID = 1 and ChannelID = 2 and ChannelID = 3
Group by ProductID

but I get no results. I thought this would be straight forward.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You are telling it to return records where the ChannelID equals 1, 2, and 3 all at the same time. Unless, you are using multi-valued fields, that is not possible and would return nothing.

I think you want to return records where ChannelID equals 1, 2, or 3, i.e.:
Code:
SELECT ProductID
FROM SalesTransaction
where (ChannelID = 1) or (ChannelID = 2) or (ChannelID = 3)
Group by ProductID
which can also be written like:
Code:
SELECT ProductID
FROM SalesTransaction
where ChannelID in  (1,2,3)
Group by ProductID
 
Upvote 0

Forum statistics

Threads
1,207,391
Messages
6,078,215
Members
446,321
Latest member
thecachingyeti

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top