Jump to content

What is wrong with this


tobeyt23

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
https://forums.phpfreaks.com/topic/3312-what-is-wrong-with-this/
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
https://forums.phpfreaks.com/topic/3312-what-is-wrong-with-this/#findComment-11293
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
https://forums.phpfreaks.com/topic/3312-what-is-wrong-with-this/#findComment-11294
Share on other sites

Archived

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

×
×
  • 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.