MySQL Forums
Forum List  »  Newbie

Selecting fields from subqueries?
Posted by: Robert Berry
Date: August 27, 2008 05:16AM

Hiya, I hope this is the right place for this, not sure where to post it ... I'm self-taught in MySQL but can't seem to find an answer for this in the manual. I was wondering in a SELECT query whether you can also return in the results fields selected from Subqueries. So, my SQL so far is like this:

SELECT cart_to_attribute.*
FROM cart
LEFT JOIN cart_to_attribute
ON(cart.cart_id = cart_to_attribute.cart_id)
WHERE cart.sessionhash = '$sessionhash'
AND (cart_to_attribute.attribute_id, cart.product_id) =
ANY
(SELECT cart_to_attribute.attribute_id, cart.product_id
FROM cart
LEFT JOIN cart_to_attribute
ON(cart.cart_id = cart_to_attribute.cart_id)
WHERE cart.user_id = $cookie_userid)

So what I'd like to do is also get the cart_id from the subquery (which is selecting by cart.user_id) returned in the results. Can this be done via subqueries or would I have to rewrite it as some sort of join?

Thanks, and apologies if I'm not supposed to post this here.

Options: ReplyQuote


Subject
Written By
Posted
Selecting fields from subqueries?
August 27, 2008 05:16AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.