Jump to content

[SOLVED] Subquery


tobeyt23
 Share

Recommended Posts

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
Share on other sites

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