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?