Re: Do I need a subquery?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

.



Relevant Pages

  • Re: Calculate the date interval between all occuring events
    ... I also tested the subquery by playing with the example at the subquery ... Save this query. ... a simple way to generate a table to show all purchase intervals by each ... customer and then be able to calculate the average intervals for each ...
    (microsoft.public.access.queries)
  • Re: 45 Days between multiple occurrences. My brain may explode! (help)
    ... Use a subquery to find the closest service. ... CustomerID relates to the primary key of your Customer table. ... If that's the kind of thing you have, create a query using Table1. ...
    (microsoft.public.access.queries)
  • Re: 45 Days between multiple occurrences. My brain may explode! (help)
    ... Use a subquery to find the closest service. ... CustomerID relates to the primary key of your Customer table. ... If that's the kind of thing you have, create a query using Table1. ...
    (microsoft.public.access.queries)
  • Re: Nasty Query Here
    ... You are using a UNION between the two halves of the SQL statement, ... You are using TRUNCin the subquery, ... email returned from the inline view is null or not. ...
    (comp.databases.oracle.misc)
  • Re: Help with a form/query
    ... Perth, Western Australia ... Tips for Access users - http://allenbrowne.com/tips.html ... There is a form that is using a query to populate a subform, ... grabs the primary key from the customer that is selected in the main form, ...
    (microsoft.public.access.queries)