MySQL Forums
Forum List  »  Newbie

Re: Can you help me to solve this query problem?
Posted by: Chris Stubben
Date: June 03, 2005 02:35PM

Hi,

Try adding DISTINCT to the two count funtions, count( DISTINCT m.user_id ), count( DISTINCT o.user_id )

Also, remove the GROUP BY and count functions and you should see why this is happening. Basically, if you use aggregate functions and multiple joins, you need to deal with the Cartesian product that's returned.


SELECT
u.user_id
, u.surname
, u.firstname
,m.user_id AS localGroupMembers
,o.user_id AS orders
FROM
users AS u
LEFT JOIN
localGroupMembers AS m
ON u.user_id = m.user_id
LEFT JOIN
orders AS o
ON u.user_id = o.user_id
WHERE
u.user_id = "aca0c71d890f426db8d010427de0527b";




Chris

Options: ReplyQuote


Subject
Written By
Posted
Re: Can you help me to solve this query problem?
June 03, 2005 02:35PM


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.