I have a query, that displays issued and returned weights for a dispensing system. I would like to be able to combine the two results, giving me the total between the issue and returned weight.
I have two tables: issue, and return. If I have the following values, how would my SELECT statement look?
issue:
job code weight
1 A 20
1 B 30
1 C 40
1 D 10
return:
job code weight
1 A 10
1 C 5
1 D 8
So, I would like my SELECT statement to return these values:
job code total used
1 A 10
1 B 30
1 C 35
1 D 2
I currently have a SELECT statement like this:
SELECT issue.job, issue.code, return.job, return.code, SUM(issue.weight) AS iss_weight, SUM(return.weight) AS rtn_weight
FROM issue LEFT JOIN return ON issue.job=return.job
WHERE issue.job = $job_id
GROUP BY issue.code
It does not give me the output I am looking for. Can anyone help?
TIA...