Page 1 of 1

SUM of Two Columns from Two Different Table

Posted: 2020-09-29 15:19
by mohamed
Hello,

I have created 3 tables:
1. GSM (stored the user name)
2. Voice_Plans (stored both PLAN Number and Charges of the Plan)
3. Phones (stored Device Name and Charges of the Device

In the GSM table
- I have a Lookup field linked to `Voice_Plans`.`Charges`
- and I have another Lookup field linked to `Phones`.`Charges`
- and created another field with name TOTAL (to show the total of the above two fields that are linked to another two tables)

in CALCULATED FIELD I have entered the following SQL command:
SELECT (`Voice_Plans`.`Charges` + `Phones`.`Charges`) FROM Voice_Plans, Phones WHERE id='%ID%'

but I am not getting the TOTAL of the above two fields, so I am wondering;
1. If what I am intending to do is possible in Calculated Field

2. secondly, is the command correct ? :|

Re: SUM of Two Columns from Two Different Table

Posted: 2020-09-30 06:14
by pbottcher
Hi,
1, yes,
2, no

:roll:

Without knowing the details of your tabledefinitons it is not possible to provide further help.

The sum is correct, but you need to join the 3 tables together based on the linked fields.

Re: SUM of Two Columns from Two Different Table

Posted: 2020-09-30 08:26
by mohamed
HI pböttcher,

You enjoy torturing me, isn't it?! :D

No worries, thanks for your comments and confirmation that it is possible 8-)

I am pushing Mr. GOOGLE to find me the solution or at least some hints, as SQL is not my play ground :)