UPDATE: Thanks a lot guys. You have my upvotes. My problem seem to be something else entirely.
I'm trying to get sum(QTY) from TBL_INVTY but I can't correctly join this table with TBL_ITEM. There is this column PARENT_CODE that complicates things for me. Let me better explain it like this...
TBL_ITEM
+------+-------------+
| CODE | PARENT_CODE |
+------+-------------+
| 2 | NULL |
| 2A | 2 |
| 2B | 2 |
| 3 | NULL |
| 4 | NULL |
+------+-------------+
TBL_INVTY
+------+-----+
| CODE | QTY |
+------+-----+
| 2 | 2 |
| 2A | 4 |
| 2B | 1 |
| 3 | 3 |
| 4 | 5 |
+------+-----+
And, arrive on this:
+------+-----+
| CODE | QTY |
+------+-----+
| 2 | 7 |
| 3 | 3 |
| 4 | 5 |
+------+-----+