Solved

How to write joint query?

Posted on 1998-10-30
1
949 Views
Last Modified: 2006-11-17
let's say i have a one table called order which contains productid, now how do i write the query which counts the number of orders which contains only two product (Ex Product A and Product B).
i try by writing one query which display product A and then second query which display product b and then i join two gather it works fine but how do i write everything in one query instead of three query.
0
Comment
Question by:bcp5190
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
rscott_young earned 20 total points
ID: 1967279
Because you can't use "SUM" in your WHERE clause you'll have to use two queries.  Below is an example of both.  Use the first query to create a temporary table and the second to select your orders:

SELECT max([Order ID]),
sum(iif([Product ID] = 'A',1,0)) as PRODUCTA,
sum(iif([Product ID] = 'B',1,0)) as PRODUCTB,
sum(iif([Product ID] <> 'A' and [Product ID] <> 'B',1,0)) AS NONAB
FROM [Orders Detail]
GROUP BY [Order ID];

SELECT Order ID
FROM Temptable
WHERE PRODUCTA > 0 and PRODUCTB > 0 and NONAB = 0
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question