I have the following SQL Query:
SELECT porel.refcode, podetail.ponum, SUM(podetail.orderqty * podetail.unitcost) AS Total
FROM podetail
LEFT JOIN porel ON podetail.ponum = porel.ponum
WHERE porel.poline=podetail.poline AND porel.reftype = 'SPEX'
GROUP BY porel.refcode, podetail.ponum
ORDER BY porel.refcode, podetail.ponum
which works fine to bring me a list of ponums and their total values against refcodes.
I now want to add a third column vendor.name. The vendor table has a field vendorid which it shares with the podetail table.
There are multiple podetail records with the same ponum but these will also have matching vendorid‘s.
Could someone advise how I would add in the vendor.name field without returning extra rows?
Heya, Rogue. I wanted to say a little more than fits in a comment, so here.
One more easy diagnostic off the top of my head is this:
In here, we don’t join to
vendorat all, taking the table completely out of the equation. Instead, we’ll just roll uppodetail.vendorids instead.Can you post the output of this query?