No, still not going to work PH. Join returns multiple rows so values in servicememo get repeated and you get the wrong sum.
$sql = "SELECT sm.id, sm.tot, smw.* FROM
(SELECT id, sum(memoTotalVPC) as tot FROM ServiceMemo WHERE id=18486 GROUP BY id, memoTotalVPC) as sm
INNER JOIN ServiceMemoWork smw ON sm.id = smw.serviceMemoID";
But even as I write that I wonder what the SUM is doing, cos you've only got 1 row in servicememo with the id=18486 ?? Whole Group By thing is unneccessary and the sum is just going to be the same as the column value cos ther is only the one. My guess is that you've not posted the code you are using, for whatever reason.
I'll leave this query as-is though as an exemplar of how you would do this with a sub-query - if you needed one. As it is this query makes no sense but the principle is there.
I can never understand why people post fake code, makes it really difficult to help them. I dunno what they are trying to hide?It's like they think someone is going to steal their 'brilliant' ideas.[/I] :bemused: