Re: Do I need a subquery?
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Mon, 18 Jun 2007 20:45:45 +0800
You want to list *all* orders for any customer who has an order in a particular period?
Yes: you need to use a subquery in the WHERE clause to handle the requirement.
The query statement will be something like this:
SELECT Orders.*
FROM Orders
WHERE EXISTS
(SELECT OrderID
FROM Orders AS Dupe
WHERE Dupe.CustomerID = Orders.CustomerID
AND Dupe.OrderDate Between #1/1/2007# And #1/1/2008#);
For help with subquery basics, see:
http://allenbrowne.com/subquery-01.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Chippy" <Chippy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:304F2905-C823-485B-8DEB-35FD6E1E1E42@xxxxxxxxxxxxxxxx
I have a customer orders table (Orders) which contains orders with and
without cost (Orders.Order_Cost).
I need a query to achieve the following logic:
Select all orders for a customer between start date and end date(including
those with no value) only if the customer has a least one order in that
period with value.
Repeat this for all customers.
Do I need to use a subquery? if so any help on query format would be much
appreciated. Thanks
.
- Prev by Date: Report on missing records
- Next by Date: Re: Print Reports and Sub Reports
- Previous by thread: Report on missing records
- Next by thread: If the date is more than 6 weeks ago....
- Index(es):
Relevant Pages
|