tobeyt23 Posted January 18, 2006 Share Posted January 18, 2006 When i do the querys together the sum for total returns nothing however when i do them seperately they work fine, what am i doing wrong here:[code]SELECT zc.* FROM zip_code zc LEFT JOIN zip_holder zh ON zc.zip_code_id=zh.zip_code_id,(SELECT SUM( zc1.quantity ) FROM zip_code zc1 LEFT JOIN zip_holder zh1 ON zc1.zip_code_id = zh1.zip_code_id WHERE zh1.cart_id='41a0efa279f4a129bb4064835b5a1fb9' GROUP BY zh1.cart_id) AS Total WHERE zh.cart_id='41a0efa279f4a129bb4064835b5a1fb9'[/code] Link to comment https://forums.phpfreaks.com/topic/3224-solved-subquery/ Share on other sites More sharing options...
fenway Posted January 18, 2006 Share Posted January 18, 2006 That is strange; but why don't you have this as a single query? Try the following (UNTESTED):[code]SELECT zc.*, SUM( zc.quantity ) AS Total FROM zip_code zc LEFT JOIN zip_holder zh ON zc.zip_code_id = zh.zip_code_id WHERE zh.cart_id='41a0efa279f4a129bb4064835b5a1fb9'[/code]Hope that helps. Link to comment https://forums.phpfreaks.com/topic/3224-solved-subquery/#findComment-10981 Share on other sites More sharing options...
tobeyt23 Posted January 18, 2006 Author Share Posted January 18, 2006 I tried this but when you did it as one you need to GROUP BY which doesn't return what i need Link to comment https://forums.phpfreaks.com/topic/3224-solved-subquery/#findComment-10983 Share on other sites More sharing options...
fenway Posted January 18, 2006 Share Posted January 18, 2006 I don't understand why -- you want the SUM() all of the matching rows with the given cartID. The GROUP BY is implicit. Please clarify. Link to comment https://forums.phpfreaks.com/topic/3224-solved-subquery/#findComment-10988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.