A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

query for one product only



 
 
Thread Tools Display Modes
  #1  
Old August 31st, 2009, 06:39 PM posted to microsoft.public.access.gettingstarted
KrispyData
external usenet poster
 
Posts: 78
Default query for one product only

I have a Customer Orders table that includes the following fields as an
example:

customer
product (socks, gloves, scarves, belts)
sales

I want to create a query for all customers that order belts exclusively.
i'm having a difficult time figureing out to create such a query. If i use
"belts" as a query criteria, it will give me every customer that orders
belts, but not customers that ONLY order belts. Can anyone offer any
suggestions?
  #2  
Old August 31st, 2009, 07:06 PM posted to microsoft.public.access.gettingstarted
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default query for one product only

Try this --
SELECT [customer]
FROM [sales]
WHERE [product] = "belts" AND [product] Not In("socks", "gloves", "scarves");


--
Build a little, test a little.


"KrispyData" wrote:

I have a Customer Orders table that includes the following fields as an
example:

customer
product (socks, gloves, scarves, belts)
sales

I want to create a query for all customers that order belts exclusively.
i'm having a difficult time figureing out to create such a query. If i use
"belts" as a query criteria, it will give me every customer that orders
belts, but not customers that ONLY order belts. Can anyone offer any
suggestions?

  #3  
Old August 31st, 2009, 07:14 PM posted to microsoft.public.access.gettingstarted
KrispyData
external usenet poster
 
Posts: 78
Default query for one product only

Thanks, Karl. What if the list of other products is more than just 4 items -
more like 100 items! Is there another way?

"KARL DEWEY" wrote:

Try this --
SELECT [customer]
FROM [sales]
WHERE [product] = "belts" AND [product] Not In("socks", "gloves", "scarves");


--
Build a little, test a little.


"KrispyData" wrote:

I have a Customer Orders table that includes the following fields as an
example:

customer
product (socks, gloves, scarves, belts)
sales

I want to create a query for all customers that order belts exclusively.
i'm having a difficult time figureing out to create such a query. If i use
"belts" as a query criteria, it will give me every customer that orders
belts, but not customers that ONLY order belts. Can anyone offer any
suggestions?

  #4  
Old August 31st, 2009, 07:49 PM posted to microsoft.public.access.gettingstarted
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default query for one product only

Two queries as I do not subqueries. First pull list of all who did not order
belts.
qryNoBelts
SELECT [customer]
FROM [sales]
WHERE [product] "belts";

SELECT [customer]
FROM [sales] LEFT JOIN [qryNoBelts] ON [sales].[customer] =
[qryNoBelts].[customer]
WHERE [customer] Is Null;


--
Build a little, test a little.


"KrispyData" wrote:

Thanks, Karl. What if the list of other products is more than just 4 items -
more like 100 items! Is there another way?

"KARL DEWEY" wrote:

Try this --
SELECT [customer]
FROM [sales]
WHERE [product] = "belts" AND [product] Not In("socks", "gloves", "scarves");


--
Build a little, test a little.


"KrispyData" wrote:

I have a Customer Orders table that includes the following fields as an
example:

customer
product (socks, gloves, scarves, belts)
sales

I want to create a query for all customers that order belts exclusively.
i'm having a difficult time figureing out to create such a query. If i use
"belts" as a query criteria, it will give me every customer that orders
belts, but not customers that ONLY order belts. Can anyone offer any
suggestions?

  #5  
Old August 31st, 2009, 07:52 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default query for one product only

Try a query that looks like the following

SELECT *
FROM [CustomerOrders]
WHERE [Customer] NOT IN
(SELECT [Customer]
FROM [CustomerOrders]
WHERE [Product] "Belt")

In query design view
== Add your table
== Select the fields you want to see
== Enter the following as criteria under Customer
NOT IN (SELECT [Customer] FROM [CustomerOrders] WHERE [Product] "Belt")
(replace the table and field names with your table and field names.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

KrispyData wrote:
I have a Customer Orders table that includes the following fields as an
example:

customer
product (socks, gloves, scarves, belts)
sales

I want to create a query for all customers that order belts exclusively.
i'm having a difficult time figureing out to create such a query. If i use
"belts" as a query criteria, it will give me every customer that orders
belts, but not customers that ONLY order belts. Can anyone offer any
suggestions?

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.