Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query problem 1

Status
Not open for further replies.

peljo

Technical User
Joined
Mar 3, 2006
Messages
91
Location
BG
I want to make a query with two conditions : to include all the orders having orders.Audit = > True and also all the orders where orders.Suborder = true.
I want to exclude the orders that have no criteria as Audit = True or Suborder = True.
I cannot do it, since in the query I have built there are also orders which have neither Audit = True or Suborder = True
How can I exclude those last order from the query? I did try to add in the where clause orders.suborder = True but the query does not give the right results

SELECT orders.orderid, orders.audit, orders.SubOrder
FROM orders INNER JOIN [order details] ON orders.orderid = [order details].OrderID
GROUP BY orders.orderid, orders.audit, orders.SubOrder
HAVING (((orders.orderid)>=(SELECT Max(orders.orderid) FROM orders WHERE orders.Audit =True)));

In our database we begin calculating from the orderid that has Audit = true. There is only one order with Audit = True, but after this order there are many orders that have Suborder = True and a lot of orders that have no restrictions.My first task is to calclate the quantities from all the orders where Audit => true or Suborder = true. I will be very grateful for any help in this difficult assignment.
I can send an example if needed.
 
Not sure to have really understood.
Perhaps this ?
Code:
SELECT orders.orderid, orders.audit, orders.SubOrder
FROM orders INNER JOIN [order details] ON orders.orderid = [order details].OrderID
WHERE orders.orderid>=(SELECT Max(orderid) FROM orders WHERE Audit=True)
AND (orders.Audit=True OR orders.Suborder=True)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top