You can use LEFT JOIN
and then get SUM
of the AMOUNT
by grouping rows with the same CUST_ID
:
SELECT t2.CUST_ID
, COALESCE(SUM(t1.AMOUNT), 0) AS TOTAL
FROM cus t2 LEFT JOIN pur t1 ON t1.CUST_ID = t2.CUST_ID
GROUP BY t2.CUST_ID
ORDER BY TOTAL
SQLFiddle
2
solved join two columns with same title but in different table