I have to modify an open source ERP for my job. It is developped in php / mysql. Theres a feature that calculates the customers outstanding debt. (I don't know if its the correct term : it is the money the client has to pay for products he allready ordered and recieved)
In the customer class, the outstanding debt is calculed as follows :
SELECT ref_contact, SUM (outstanding_debt) outstanding_debt
FROM (SELECT ref_contact, MAX(including_tax_and_VAT_amout) outstanding_debt
FROM (SELECT ref_contact, SUM(ROUND(qty * unit_price)
and it continues. But the part I don't understand is right there : Its the SELECT statement with a SELECT in the FROM. I've never seen something like this. What does it means ?