What i'm trying to do is:
I have one TableA contains all records.
account | name | items | amount
0017532 A 3 1500
0034524 B 5 700
7772618 C 7 300
5467382 D 2 450
7772618 C 6 2200
another TableB contains:
account | name | items | amount
0034524 B 2 200
5467382 D 1 50
6483232 E 1 25
Desired query result is:
account | name | items | amount
0017532 A 3 1500
0034524 B 3 500
7772618 C 7 300
5467382 D 1 400
6483232 E 1 25
7772618 C 6 2200
If there's record in TableB then TableA.item - TableB.item and TableB.amount - TableB.amount
The result should contain all record from table A and the result of above subtraction.
I join TableA and TableB and perform minus operation but the result return only for the records that match with number of record in TableB
account | name | items | amount
0034524 B 3 500
5467382 D 1 400
6483232 E 1 25
When I try UNION above subtraction query with query TableA, it turned out that the record for both table are listed all:
account | name | items | amount
0017532 A 3 1500
0034524 B 5 700
0034524 B 3 500
7772618 C 7 300
5467382 D 2 450
5467382 D 1 400
7772618 C 6 2200
6483232 E 1 25
I'm trying to find a way to select only records from TableB if its 'account' and 'name' exist in TableA.
postgresql,oracle,sql-server,db2, ... - a_horse_with_no_name