On Tue, Apr 8, 2008 at 7:28 AM, Steven Macintyre
<[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have the following SQL statement;
>
> SELECT count( salesID ) AS count, branch_name, company_name, branch.branchID
> FROM sales
> LEFT JOIN IGuser ON sales.IGuid = IGuser.IGuid
> LEFT JOIN branch ON IGuser.branchID = branch.branchID
> LEFT JOIN company ON branch.companyID = '{$companyID}'
> WHERE maincompanyid = '{$mcid}'
> GROUP BY branch.branchID
> ORDER BY branch_name ASC
>
> However, i do not want those join records to be appended, only to return the
> count of records from sales.
>
> Can someone assist me with this? I have tried differance variants of joins
> and none of the results are correct.
>
> Sales tbl doesnt have the companyID, nor does IGuser
>
> Regards,
>
> Steven
A couple things:
1) Are you looking for COUNT(DISTINCT salesID) rather than COUNT(salesID)?
2) Change your group clause to this: GROUP BY branch.branchID,
branch_name, company name
MySQL is pretty forgiving and will let you include fields in the
SELECT that are neither aggregated nor grouped, but it's bad practice.
Beyond that, a clearer explanation of what you expect to see in the
results would help a lot in building the query to get those results.
Andrew
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php