Hi Igor, Thanks for replying.
> BareFeet <[EMAIL PROTECTED]> wrote: >> I tried this: >> >> select >> "Invoices".ID as Invoice >> , (select sum(Buy) from Moves where Moves.Invoice = Invoices.ID) >> as "Sum Buy" >> , (select sum(Delivery) from "Orders" on "Orders".ID in (select >> "Order" from Moves where Invoice = Invoices.ID)) as "Sum Delivery" >> from "Invoices" >> group by Invoice >> ; >> >> which works correctly but it seems inelegant, inefficient and in one >> test seems orders of magnitude too slow. > > Drop GROUP BY clause, you don't need it here. See if it helps with > performance. You are quite right, the group by clause was leftover from describing my other approaches. So is there no better way to achieve this result? Is it not possible to use a join here to avoid the triple nested selects, the "in" clause and the duplicated "where Moves.Invoice = Invoices.ID" reference? Thanks, Tom BareFeet _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users