Jump to content

Archived

This topic is now archived and is closed to further replies.

tobeyt23

What is wrong with this

Recommended Posts

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]

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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 sumQuantity

WHERE zip_tracker.order_id='50'[/code]

Hope that helps.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.