Jump to content

What is wrong with this


tobeyt23
 Share

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]
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

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.