MySQL Forums
Forum List  »  Newbie

total fields in both tables in a 1:many join
Posted by: adam island
Date: January 19, 2009 03:51PM

i have 2 tables. orders and order items. i want to find the total value of the items sold and the total order total (which would be different than product value due to taxes and shipping) is there a way to do this.

orders
------
id
date
total

orderitems
------
id
order_id
value



i can't say "select sum(orders.total), sum(orderitems.value) from orders, orderitems where orders.id=orderitems.order_id" because once they join, if there are 2 items in an order, they order.total is added twice for that order, making the final value way too high.

Options: ReplyQuote


Subject
Written By
Posted
total fields in both tables in a 1:many join
January 19, 2009 03:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.