tobeyt23 Posted February 3, 2006 Share Posted February 3, 2006 Keeps telling me Every derived table must have its own alias for the following:[code]SELECT zip_code.* FROM zip_code LEFT JOIN zip_tracker ON zip_code.zip_code_id=zip_tracker.zip_code_id,(SELECT SUM(zc.quantity) AS total FROM zip_code as zc LEFT JOIN zip_tracker zt ON zc.zip_code_id=zt.zip_code_id WHERE zt.order_id='50') WHERE zip_tracker.order_id='50'[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3312-what-is-wrong-with-this/ Share on other sites More sharing options...
radox Posted February 3, 2006 Share Posted February 3, 2006 [!--quoteo(post=342403:date=Feb 3 2006, 09:26 AM:name=tobeyt23)--][div class=\'quotetop\']QUOTE(tobeyt23 @ Feb 3 2006, 09:26 AM) [snapback]342403[/snapback][/div][div class=\'quotemain\'][!--quotec--]Keeps telling me Every derived table must have its own alias for the following:[code]SELECT zip_code.* FROM zip_code LEFT JOIN zip_tracker ON zip_code.zip_code_id=zip_tracker.zip_code_id,(SELECT SUM(zc.quantity) AS total FROM zip_code as zc LEFT JOIN zip_tracker zt ON zc.zip_code_id=zt.zip_code_id WHERE zt.order_id='50') WHERE zip_tracker.order_id='50'[/code][/quote]should be[code]SELECT zip_code.* FROM zip_code LEFT JOIN zip_tracker ON zip_code.zip_code_id=zip_tracker.zip_code_id,(SELECT SUM(zc.quantity) AS total FROM zip_code as zc LEFT JOIN zip_tracker AS zt ON zc.zip_code_id=zt.zip_code_id WHERE zt.order_id='50') WHERE zip_tracker.order_id='50'[/code]looks like you just forgot an "AS" for zt Quote Link to comment https://forums.phpfreaks.com/topic/3312-what-is-wrong-with-this/#findComment-11293 Share on other sites More sharing options...
fenway Posted February 3, 2006 Share Posted February 3, 2006 No, that's not it -- the AS is optional. However, you _do_ need to give your SUM sub-query a column alias, e.g.:[code]SELECT zip_code.* FROM zip_code LEFT JOIN zip_tracker ON zip_code.zip_code_id=zip_tracker.zip_code_id,(SELECT SUM(zc.quantity) AS total FROM zip_code as zc LEFT JOIN zip_tracker zt ON zc.zip_code_id=zt.zip_code_id WHERE zt.order_id='50') AS sumQuantityWHERE zip_tracker.order_id='50'[/code]Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/3312-what-is-wrong-with-this/#findComment-11294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.