marc312 Posted May 9, 2007 Share Posted May 9, 2007 Can someone please help me with some query syntax? I'm trying to do a joint query to find total sales for orders which were a customer's first order only. Basically, I need to join these two queries, which I already know work in their own respects: Take total sales for all orders: select sum(ot.value) as total from orders o, orders_total ot where ot.class='ot_total' and ot.orders_id=o.orders_id Find first orders: select distinct(o.customers_id) from orders o, customers_info ci where ci.customers_info_id = o.customers_id It seems to me that I should be able to join these in the following way: select sum(ot.value) as total from orders o, orders_total ot where ot.class='ot_total' and ot.orders_id=o.orders_id in (select distinct(o.customers_id) from orders o, customers_info ci where ci.customers_info_id = o.customers_id) However, the above makes my database server hang. Any suggestions? I'd really appreciate the help! -Marc Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.